put-datafeed.asciidoc 4.6 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. * 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. 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 detector configuration objects in a
  80. job can contain functions that use these script fields. For more information,
  81. see <<request-body-search-script-fields,Script fields>>.
  82. `scroll_size`::
  83. (Optional, unsigned integer) The `size` parameter that is used in {es}
  84. searches. The default value is `1000`.
  85. For more information about these properties,
  86. see <<ml-datafeed-resource>>.
  87. [[ml-put-datafeed-example]]
  88. ==== {api-examples-title}
  89. The following example creates the `datafeed-total-requests` {dfeed}:
  90. [source,console]
  91. --------------------------------------------------
  92. PUT _ml/datafeeds/datafeed-total-requests
  93. {
  94. "job_id": "total-requests",
  95. "indices": ["server-metrics"]
  96. }
  97. --------------------------------------------------
  98. // TEST[skip:setup:server_metrics_job]
  99. When the {dfeed} is created, you receive the following results:
  100. [source,console-result]
  101. ----
  102. {
  103. "datafeed_id": "datafeed-total-requests",
  104. "job_id": "total-requests",
  105. "query_delay": "83474ms",
  106. "indices": [
  107. "server-metrics"
  108. ],
  109. "query": {
  110. "match_all": {
  111. "boost": 1.0
  112. }
  113. },
  114. "scroll_size": 1000,
  115. "chunking_config": {
  116. "mode": "auto"
  117. }
  118. }
  119. ----
  120. // TESTRESPONSE[s/"query_delay": "83474ms"/"query_delay": $body.query_delay/]
  121. // TESTRESPONSE[s/"query.boost": "1.0"/"query.boost": $body.query.boost/]