put-datafeed.asciidoc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 a 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 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) The interval at which scheduled queries are made while
  52. the {dfeed} runs in real time. The default value is either the bucket span for
  53. short bucket spans, or, for longer bucket spans, a sensible fraction of the
  54. 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. `job_id`::
  59. (Required, string) A numerical character string that uniquely identifies the
  60. job.
  61. `query`::
  62. (Optional, object) The {es} query domain-specific language (DSL). This value
  63. corresponds to the query object in an {es} search POST body. All the options
  64. that are supported by {Es} can be used, as this object is passed verbatim to
  65. {es}. By default, this property has the following value:
  66. `{"match_all": {"boost": 1}}`.
  67. `query_delay`::
  68. (Optional, time units) The number of seconds behind real time that data is
  69. queried. For example, if data from 10:04 a.m. might not be searchable in {es}
  70. until 10:06 a.m., set this property to 120 seconds. The default value is `60s`.
  71. `script_fields`::
  72. (Optional, object) Specifies scripts that evaluate custom expressions and
  73. returns script fields to the {dfeed}. The
  74. <<ml-detectorconfig,detector configuration objects>> in a job can contain
  75. functions that use these script fields. For more information, see
  76. <<request-body-search-script-fields,Script fields>>.
  77. `scroll_size`::
  78. (Optional, unsigned integer) The `size` parameter that is used in {es}
  79. searches. The default value is `1000`.
  80. For more information about these properties,
  81. see <<ml-datafeed-resource>>.
  82. [[ml-put-datafeed-example]]
  83. ==== {api-examples-title}
  84. The following example creates the `datafeed-total-requests` {dfeed}:
  85. [source,js]
  86. --------------------------------------------------
  87. PUT _ml/datafeeds/datafeed-total-requests
  88. {
  89. "job_id": "total-requests",
  90. "indices": ["server-metrics"]
  91. }
  92. --------------------------------------------------
  93. // CONSOLE
  94. // TEST[skip:setup:server_metrics_job]
  95. When the {dfeed} is created, you receive the following results:
  96. [source,js]
  97. ----
  98. {
  99. "datafeed_id": "datafeed-total-requests",
  100. "job_id": "total-requests",
  101. "query_delay": "83474ms",
  102. "indices": [
  103. "server-metrics"
  104. ],
  105. "query": {
  106. "match_all": {
  107. "boost": 1.0
  108. }
  109. },
  110. "scroll_size": 1000,
  111. "chunking_config": {
  112. "mode": "auto"
  113. }
  114. }
  115. ----
  116. // TESTRESPONSE[s/"query_delay": "83474ms"/"query_delay": $body.query_delay/]
  117. // TESTRESPONSE[s/"query.boost": "1.0"/"query.boost": $body.query.boost/]