put-datafeed.asciidoc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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-desc]]
  14. ==== {api-description-title}
  15. You must create a job before you create a {dfeed}. You can associate only one
  16. {dfeed} to each job.
  17. IMPORTANT: You must use {kib} or this API to create a {dfeed}. Do not put a {dfeed}
  18. directly to the `.ml-config` index using the Elasticsearch index API.
  19. If {es} {security-features} are enabled, do not give users `write`
  20. privileges on the `.ml-config` index.
  21. [[ml-put-datafeed-path-parms]]
  22. ==== {api-path-parms-title}
  23. `feed_id` (required)::
  24. (string) A numerical character string that uniquely identifies the {dfeed}.
  25. This identifier can contain lowercase alphanumeric characters (a-z and 0-9),
  26. hyphens, and underscores. It must start and end with alphanumeric characters.
  27. [[ml-put-datafeed-request-body]]
  28. ==== {api-request-body-title}
  29. `aggregations`::
  30. (object) If set, the {dfeed} performs aggregation searches.
  31. For more information, see <<ml-datafeed-resource>>.
  32. `chunking_config`::
  33. (object) Specifies how data searches are split into time chunks.
  34. See <<ml-datafeed-chunking-config>>.
  35. `delayed_data_check_config`::
  36. (object) Specifies whether the data feed checks for missing data and
  37. the size of the window. See
  38. <<ml-datafeed-delayed-data-check-config>>.
  39. `frequency`::
  40. (time units) The interval at which scheduled queries are made while the {dfeed}
  41. runs in real time. The default value is either the bucket span for short
  42. bucket spans, or, for longer bucket spans, a sensible fraction of the bucket
  43. span. For example: `150s`.
  44. `indices` (required)::
  45. (array) An array of index names. Wildcards are supported. For example:
  46. `["it_ops_metrics", "server*"]`.
  47. `job_id` (required)::
  48. (string) A numerical character string that uniquely identifies the job.
  49. `query`::
  50. (object) The {es} query domain-specific language (DSL). This value
  51. corresponds to the query object in an {es} search POST body. All the
  52. options that are supported by {Es} can be used, as this object is
  53. passed verbatim to {es}. By default, this property has the following
  54. value: `{"match_all": {"boost": 1}}`.
  55. `query_delay`::
  56. (time units) The number of seconds behind real time that data is queried. For
  57. example, if data from 10:04 a.m. might not be searchable in {es} until
  58. 10:06 a.m., set this property to 120 seconds. The default value is `60s`.
  59. `script_fields`::
  60. (object) Specifies scripts that evaluate custom expressions and returns
  61. script fields to the {dfeed}.
  62. The <<ml-detectorconfig,detector configuration objects>> in a job can contain
  63. functions that use these script fields.
  64. For more information,
  65. see {ref}/search-request-script-fields.html[Script Fields].
  66. `scroll_size`::
  67. (unsigned integer) The `size` parameter that is used in {es} searches.
  68. The default value is `1000`.
  69. For more information about these properties,
  70. see <<ml-datafeed-resource>>.
  71. [[ml-put-datafeed-prereqs]]
  72. ==== {api-prereq-title}
  73. If {es} {security-features} are enabled, you must have `manage_ml`, or `manage`
  74. cluster privileges to use this API. For more information, see
  75. {stack-ov}/security-privileges.html[Security privileges].
  76. [[ml-put-datafeed-security]]
  77. ==== Security integration
  78. When {es} {security-features} are enabled, your {dfeed} remembers which roles the
  79. user who created it had at the time of creation and runs the query using those
  80. same roles.
  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/]