put-datafeed.asciidoc 4.4 KB

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