put-datafeed.asciidoc 3.9 KB

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