put-datafeed.asciidoc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. {stack-ov}/security-privileges.html[Security privileges].
  19. [[ml-put-datafeed-desc]]
  20. ==== {api-description-title}
  21. You can associate only one {dfeed} to each {anomaly-job}.
  22. [IMPORTANT]
  23. ====
  24. * You must use {kib} or this API to create a {dfeed}. Do not put a
  25. {dfeed} directly to the `.ml-config` index using the {es} index API. If {es}
  26. {security-features} are enabled, do not give users `write` privileges on the
  27. `.ml-config` index.
  28. * When {es} {security-features} are enabled, your {dfeed} remembers which roles
  29. the user who created it had at the time of creation and runs the query using
  30. those same roles.
  31. ====
  32. [[ml-put-datafeed-path-parms]]
  33. ==== {api-path-parms-title}
  34. `<feed_id>`::
  35. (Required, string) A numerical character string that uniquely identifies the
  36. {dfeed}. This identifier can contain lowercase alphanumeric characters (a-z
  37. and 0-9), hyphens, and underscores. It must start and end with alphanumeric
  38. characters.
  39. [[ml-put-datafeed-request-body]]
  40. ==== {api-request-body-title}
  41. `aggregations`::
  42. (Optional, object) If set, the {dfeed} performs aggregation searches. For more
  43. information, see <<ml-datafeed-resource>>.
  44. `chunking_config`::
  45. (Optional, object) Specifies how data searches are split into time chunks. See
  46. <<ml-datafeed-chunking-config>>.
  47. `delayed_data_check_config`::
  48. (Optional, object) Specifies whether the data feed checks for missing data and
  49. the size of the window. See <<ml-datafeed-delayed-data-check-config>>.
  50. `frequency`::
  51. (Optional, <<time-units, time units>>) The interval at which scheduled queries
  52. are made while the {dfeed} runs in real time. The default value is either the
  53. bucket span for short bucket spans, or, for longer bucket spans, a sensible
  54. fraction of the bucket span. For example: `150s`.
  55. `indices`::
  56. (Required, array) An array of index names. Wildcards are supported. For
  57. example: `["it_ops_metrics", "server*"]`.
  58. +
  59. --
  60. NOTE: If any indices are in remote clusters then `cluster.remote.connect` must
  61. not be set to `false` on any ML node.
  62. --
  63. `job_id`::
  64. (Required, string) A numerical character string that uniquely identifies the
  65. {anomaly-job}.
  66. `query`::
  67. (Optional, object) The {es} query domain-specific language (DSL). This value
  68. corresponds to the query object in an {es} search POST body. All the options
  69. that are supported by {Es} can be used, as this object is passed verbatim to
  70. {es}. By default, this property has the following value:
  71. `{"match_all": {"boost": 1}}`.
  72. `query_delay`::
  73. (Optional, <<time-units, time units>>) The number of seconds behind real time
  74. that data is queried. For example, if data from 10:04 a.m. might not be
  75. searchable in {es} until 10:06 a.m., set this property to 120 seconds. The
  76. default value is `60s`.
  77. `script_fields`::
  78. (Optional, object) Specifies scripts that evaluate custom expressions and
  79. returns script fields to the {dfeed}. The
  80. <<ml-detectorconfig,detector configuration objects>> in a job can contain
  81. functions that use these script fields. For more information, see
  82. <<request-body-search-script-fields,Script fields>>.
  83. `scroll_size`::
  84. (Optional, unsigned integer) The `size` parameter that is used in {es}
  85. searches. The default value is `1000`.
  86. For more information about these properties,
  87. see <<ml-datafeed-resource>>.
  88. [[ml-put-datafeed-example]]
  89. ==== {api-examples-title}
  90. The following example creates the `datafeed-total-requests` {dfeed}:
  91. [source,console]
  92. --------------------------------------------------
  93. PUT _ml/datafeeds/datafeed-total-requests
  94. {
  95. "job_id": "total-requests",
  96. "indices": ["server-metrics"]
  97. }
  98. --------------------------------------------------
  99. // TEST[skip:setup:server_metrics_job]
  100. When the {dfeed} is created, you receive the following results:
  101. [source,console-result]
  102. ----
  103. {
  104. "datafeed_id": "datafeed-total-requests",
  105. "job_id": "total-requests",
  106. "query_delay": "83474ms",
  107. "indices": [
  108. "server-metrics"
  109. ],
  110. "query": {
  111. "match_all": {
  112. "boost": 1.0
  113. }
  114. },
  115. "scroll_size": 1000,
  116. "chunking_config": {
  117. "mode": "auto"
  118. }
  119. }
  120. ----
  121. // TESTRESPONSE[s/"query_delay": "83474ms"/"query_delay": $body.query_delay/]
  122. // TESTRESPONSE[s/"query.boost": "1.0"/"query.boost": $body.query.boost/]