put-datafeed.asciidoc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[ml-put-datafeed]]
  4. = Create {dfeeds} API
  5. [subs="attributes"]
  6. ++++
  7. <titleabbrev>Create {dfeeds}</titleabbrev>
  8. ++++
  9. Instantiates a {dfeed}.
  10. [[ml-put-datafeed-request]]
  11. == {api-request-title}
  12. `PUT _ml/datafeeds/<feed_id>`
  13. [[ml-put-datafeed-prereqs]]
  14. == {api-prereq-title}
  15. * You must create an {anomaly-job} before you create a {dfeed}.
  16. * Requires the following privileges:
  17. ** cluster: `manage_ml` (the `machine_learning_admin` built-in role grants this
  18. privilege)
  19. ** source index configured in the {dfeed}: `read`
  20. [[ml-put-datafeed-desc]]
  21. == {api-description-title}
  22. {ml-docs}/ml-dfeeds.html[{dfeeds-cap}] retrieve data from {es} for analysis by
  23. an {anomaly-job}. You can associate only one {dfeed} to each {anomaly-job}.
  24. The {dfeed} contains a query that runs at a defined interval (`frequency`). If
  25. you are concerned about delayed data, you can add a delay (`query_delay`) at
  26. each interval. See {ml-docs}/ml-delayed-data-detection.html[Handling delayed data].
  27. [IMPORTANT]
  28. ====
  29. * You must use {kib}, this API, or the <<ml-put-job,create {anomaly-jobs} API>>
  30. to create a {dfeed}. Do not add a {dfeed} directly to the `.ml-config` index
  31. using the {es} index API. If {es} {security-features} are enabled, do not give
  32. users `write` privileges on the `.ml-config` index.
  33. * When {es} {security-features} are enabled, your {dfeed} remembers which roles
  34. the user who created it had at the time of creation and runs the query using
  35. those same roles. If you provide
  36. <<http-clients-secondary-authorization,secondary authorization headers>>, those
  37. credentials are used instead.
  38. ====
  39. [[ml-put-datafeed-path-parms]]
  40. == {api-path-parms-title}
  41. `<feed_id>`::
  42. (Required, string)
  43. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=datafeed-id]
  44. [role="child_attributes"]
  45. [[ml-put-datafeed-request-body]]
  46. == {api-request-body-title}
  47. `aggregations`::
  48. (Optional, object)
  49. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=aggregations]
  50. `chunking_config`::
  51. (Optional, object)
  52. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=chunking-config]
  53. +
  54. .Properties of `chunking_config`
  55. [%collapsible%open]
  56. ====
  57. `mode`:::
  58. (string)
  59. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=mode]
  60. `time_span`:::
  61. (<<time-units,time units>>)
  62. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=time-span]
  63. ====
  64. `delayed_data_check_config`::
  65. (Optional, object)
  66. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=delayed-data-check-config]
  67. +
  68. .Properties of `delayed_data_check_config`
  69. [%collapsible%open]
  70. ====
  71. `check_window`::
  72. (<<time-units,time units>>)
  73. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=delayed-data-check-config-check-window]
  74. `enabled`::
  75. (Boolean)
  76. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=delayed-data-check-config-enabled]
  77. ====
  78. `frequency`::
  79. (Optional, <<time-units, time units>>)
  80. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=frequency]
  81. `indices`::
  82. (Required, array)
  83. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=indices]
  84. `indices_options`::
  85. (Optional, object)
  86. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=indices-options]
  87. `job_id`::
  88. (Required, string)
  89. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]
  90. `max_empty_searches`::
  91. (Optional,integer)
  92. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=max-empty-searches]
  93. `query`::
  94. (Optional, object)
  95. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=query]
  96. `query_delay`::
  97. (Optional, <<time-units, time units>>)
  98. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=query-delay]
  99. `runtime_mappings`::
  100. (Optional, object)
  101. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=runtime-mappings]
  102. `script_fields`::
  103. (Optional, object)
  104. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=script-fields]
  105. `scroll_size`::
  106. (Optional, unsigned integer)
  107. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=scroll-size]
  108. [[ml-put-datafeed-example]]
  109. == {api-examples-title}
  110. [source,console]
  111. --------------------------------------------------
  112. PUT _ml/datafeeds/datafeed-total-requests
  113. {
  114. "job_id": "total-requests",
  115. "indices": ["server-metrics"]
  116. }
  117. --------------------------------------------------
  118. // TEST[skip:setup:server_metrics_job]
  119. When the {dfeed} is created, you receive the following results:
  120. [source,console-result]
  121. ----
  122. {
  123. "datafeed_id": "datafeed-total-requests",
  124. "job_id": "total-requests",
  125. "query_delay": "83474ms",
  126. "indices": [
  127. "server-metrics"
  128. ],
  129. "query": {
  130. "match_all": {
  131. "boost": 1.0
  132. }
  133. },
  134. "scroll_size": 1000,
  135. "chunking_config": {
  136. "mode": "auto"
  137. }
  138. }
  139. ----
  140. // TESTRESPONSE[s/"query_delay": "83474ms"/"query_delay": $body.query_delay/]
  141. // TESTRESPONSE[s/"query.boost": "1.0"/"query.boost": $body.query.boost/]