1
0

put-datafeed.asciidoc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. [role="child_attributes"]
  44. [[ml-put-datafeed-request-body]]
  45. == {api-request-body-title}
  46. `aggregations`::
  47. (Optional, object)
  48. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=aggregations]
  49. `chunking_config`::
  50. (Optional, object)
  51. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=chunking-config]
  52. +
  53. .Properties of `chunking_config`
  54. [%collapsible%open]
  55. ====
  56. `mode`:::
  57. (string)
  58. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=mode]
  59. `time_span`:::
  60. (<<time-units,time units>>)
  61. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=time-span]
  62. ====
  63. `delayed_data_check_config`::
  64. (Optional, object)
  65. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=delayed-data-check-config]
  66. +
  67. .Properties of `delayed_data_check_config`
  68. [%collapsible%open]
  69. ====
  70. `check_window`::
  71. (<<time-units,time units>>)
  72. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=delayed-data-check-config-check-window]
  73. `enabled`::
  74. (Boolean)
  75. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=delayed-data-check-config-enabled]
  76. ====
  77. `frequency`::
  78. (Optional, <<time-units, time units>>)
  79. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=frequency]
  80. `indices`::
  81. (Required, array)
  82. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=indices]
  83. `indices_options`::
  84. (Optional, object)
  85. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=indices-options]
  86. `job_id`::
  87. (Required, string)
  88. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]
  89. `max_empty_searches`::
  90. (Optional,integer)
  91. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=max-empty-searches]
  92. `query`::
  93. (Optional, object)
  94. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=query]
  95. `query_delay`::
  96. (Optional, <<time-units, time units>>)
  97. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=query-delay]
  98. `runtime_mappings`::
  99. (Optional, object)
  100. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=runtime-mappings]
  101. `script_fields`::
  102. (Optional, object)
  103. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=script-fields]
  104. `scroll_size`::
  105. (Optional, unsigned integer)
  106. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=scroll-size]
  107. [[ml-put-datafeed-example]]
  108. == {api-examples-title}
  109. [source,console]
  110. --------------------------------------------------
  111. PUT _ml/datafeeds/datafeed-total-requests
  112. {
  113. "job_id": "total-requests",
  114. "indices": ["server-metrics"]
  115. }
  116. --------------------------------------------------
  117. // TEST[skip:setup:server_metrics_job]
  118. When the {dfeed} is created, you receive the following results:
  119. [source,console-result]
  120. ----
  121. {
  122. "datafeed_id": "datafeed-total-requests",
  123. "job_id": "total-requests",
  124. "query_delay": "83474ms",
  125. "indices": [
  126. "server-metrics"
  127. ],
  128. "query": {
  129. "match_all": {
  130. "boost": 1.0
  131. }
  132. },
  133. "scroll_size": 1000,
  134. "chunking_config": {
  135. "mode": "auto"
  136. }
  137. }
  138. ----
  139. // TESTRESPONSE[s/"query_delay": "83474ms"/"query_delay": $body.query_delay/]
  140. // TESTRESPONSE[s/"query.boost": "1.0"/"query.boost": $body.query.boost/]