put-datafeed.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <<security-privileges>> and
  18. {ml-docs-setup-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. 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. `delayed_data_check_config`::
  53. (Optional, object)
  54. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=delayed-data-check-config]
  55. `frequency`::
  56. (Optional, <<time-units, time units>>)
  57. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=frequency]
  58. `indices`::
  59. (Required, array)
  60. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=indices]
  61. `job_id`::
  62. (Required, string)
  63. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]
  64. `max_empty_searches`::
  65. (Optional,integer)
  66. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=max-empty-searches]
  67. `query`::
  68. (Optional, object)
  69. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=query]
  70. `query_delay`::
  71. (Optional, <<time-units, time units>>)
  72. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=query-delay]
  73. `script_fields`::
  74. (Optional, object)
  75. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=script-fields]
  76. `scroll_size`::
  77. (Optional, unsigned integer)
  78. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=scroll-size]
  79. `indices_options`::
  80. (Optional, object)
  81. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=indices-options]
  82. [[ml-put-datafeed-example]]
  83. == {api-examples-title}
  84. [source,console]
  85. --------------------------------------------------
  86. PUT _ml/datafeeds/datafeed-total-requests
  87. {
  88. "job_id": "total-requests",
  89. "indices": ["server-metrics"]
  90. }
  91. --------------------------------------------------
  92. // TEST[skip:setup:server_metrics_job]
  93. When the {dfeed} is created, you receive the following results:
  94. [source,console-result]
  95. ----
  96. {
  97. "datafeed_id": "datafeed-total-requests",
  98. "job_id": "total-requests",
  99. "query_delay": "83474ms",
  100. "indices": [
  101. "server-metrics"
  102. ],
  103. "query": {
  104. "match_all": {
  105. "boost": 1.0
  106. }
  107. },
  108. "scroll_size": 1000,
  109. "chunking_config": {
  110. "mode": "auto"
  111. }
  112. }
  113. ----
  114. // TESTRESPONSE[s/"query_delay": "83474ms"/"query_delay": $body.query_delay/]
  115. // TESTRESPONSE[s/"query.boost": "1.0"/"query.boost": $body.query.boost/]