put-datafeed.asciidoc 5.1 KB

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