put-datafeed.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. * If {es} {security-features} are enabled, you must have `manage_ml` or `manage`
  17. cluster privileges to use this API. See
  18. <<security-privileges>>.
  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} or this API to create a {dfeed}. Do not put a
  29. {dfeed} directly to the `.ml-config` index using the {es} index API. If {es}
  30. {security-features} are enabled, do not give users `write` privileges on the
  31. `.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.
  35. ====
  36. [[ml-put-datafeed-path-parms]]
  37. ==== {api-path-parms-title}
  38. `<feed_id>`::
  39. (Required, string)
  40. include::{docdir}/ml/ml-shared.asciidoc[tag=datafeed-id]
  41. [role="child_attributes"]
  42. [[ml-put-datafeed-request-body]]
  43. ==== {api-request-body-title}
  44. `aggregations`::
  45. (Optional, object)
  46. include::{docdir}/ml/ml-shared.asciidoc[tag=aggregations]
  47. `chunking_config`::
  48. (Optional, object)
  49. include::{docdir}/ml/ml-shared.asciidoc[tag=chunking-config]
  50. `delayed_data_check_config`::
  51. (Optional, object)
  52. include::{docdir}/ml/ml-shared.asciidoc[tag=delayed-data-check-config]
  53. `frequency`::
  54. (Optional, <<time-units, time units>>)
  55. include::{docdir}/ml/ml-shared.asciidoc[tag=frequency]
  56. `indices`::
  57. (Required, array)
  58. include::{docdir}/ml/ml-shared.asciidoc[tag=indices]
  59. `job_id`::
  60. (Required, string)
  61. include::{docdir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]
  62. `max_empty_searches`::
  63. (Optional,integer)
  64. include::{docdir}/ml/ml-shared.asciidoc[tag=max-empty-searches]
  65. `query`::
  66. (Optional, object)
  67. include::{docdir}/ml/ml-shared.asciidoc[tag=query]
  68. `query_delay`::
  69. (Optional, <<time-units, time units>>)
  70. include::{docdir}/ml/ml-shared.asciidoc[tag=query-delay]
  71. `script_fields`::
  72. (Optional, object)
  73. include::{docdir}/ml/ml-shared.asciidoc[tag=script-fields]
  74. `scroll_size`::
  75. (Optional, unsigned integer)
  76. include::{docdir}/ml/ml-shared.asciidoc[tag=scroll-size]
  77. `indices_options`::
  78. (Optional, object)
  79. include::{docdir}/ml/ml-shared.asciidoc[tag=indices-options]
  80. [[ml-put-datafeed-example]]
  81. ==== {api-examples-title}
  82. [source,console]
  83. --------------------------------------------------
  84. PUT _ml/datafeeds/datafeed-total-requests
  85. {
  86. "job_id": "total-requests",
  87. "indices": ["server-metrics"]
  88. }
  89. --------------------------------------------------
  90. // TEST[skip:setup:server_metrics_job]
  91. When the {dfeed} is created, you receive the following results:
  92. [source,console-result]
  93. ----
  94. {
  95. "datafeed_id": "datafeed-total-requests",
  96. "job_id": "total-requests",
  97. "query_delay": "83474ms",
  98. "indices": [
  99. "server-metrics"
  100. ],
  101. "query": {
  102. "match_all": {
  103. "boost": 1.0
  104. }
  105. },
  106. "scroll_size": 1000,
  107. "chunking_config": {
  108. "mode": "auto"
  109. }
  110. }
  111. ----
  112. // TESTRESPONSE[s/"query_delay": "83474ms"/"query_delay": $body.query_delay/]
  113. // TESTRESPONSE[s/"query.boost": "1.0"/"query.boost": $body.query.boost/]