put-datafeed.asciidoc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[ml-put-datafeed]]
  4. === Create {dfeeds} API
  5. ++++
  6. <titleabbrev>Create {dfeeds}</titleabbrev>
  7. ++++
  8. Instantiates a {dfeed}.
  9. ==== Request
  10. `PUT _ml/datafeeds/<feed_id>`
  11. ==== Description
  12. You must create a job before you create a {dfeed}. You can associate only one
  13. {dfeed} to each job.
  14. IMPORTANT: You must use {kib} or this API to create a {dfeed}. Do not put a {dfeed}
  15. directly to the `.ml-config` index using the Elasticsearch index API.
  16. If {es} {security-features} are enabled, do not give users `write`
  17. privileges on the `.ml-config` index.
  18. ==== Path Parameters
  19. `feed_id` (required)::
  20. (string) A numerical character string that uniquely identifies the {dfeed}.
  21. This identifier can contain lowercase alphanumeric characters (a-z and 0-9),
  22. hyphens, and underscores. It must start and end with alphanumeric characters.
  23. ==== Request Body
  24. `aggregations`::
  25. (object) If set, the {dfeed} performs aggregation searches.
  26. For more information, see <<ml-datafeed-resource>>.
  27. `chunking_config`::
  28. (object) Specifies how data searches are split into time chunks.
  29. See <<ml-datafeed-chunking-config>>.
  30. `frequency`::
  31. (time units) The interval at which scheduled queries are made while the {dfeed}
  32. runs in real time. The default value is either the bucket span for short
  33. bucket spans, or, for longer bucket spans, a sensible fraction of the bucket
  34. span. For example: `150s`.
  35. `indices` (required)::
  36. (array) An array of index names. Wildcards are supported. For example:
  37. `["it_ops_metrics", "server*"]`.
  38. `job_id` (required)::
  39. (string) A numerical character string that uniquely identifies the job.
  40. `query`::
  41. (object) The {es} query domain-specific language (DSL). This value
  42. corresponds to the query object in an {es} search POST body. All the
  43. options that are supported by {Es} can be used, as this object is
  44. passed verbatim to {es}. By default, this property has the following
  45. value: `{"match_all": {"boost": 1}}`.
  46. `query_delay`::
  47. (time units) The number of seconds behind real time that data is queried. For
  48. example, if data from 10:04 a.m. might not be searchable in {es} until
  49. 10:06 a.m., set this property to 120 seconds. The default value is `60s`.
  50. `script_fields`::
  51. (object) Specifies scripts that evaluate custom expressions and returns
  52. script fields to the {dfeed}.
  53. The <<ml-detectorconfig,detector configuration objects>> in a job can contain
  54. functions that use these script fields.
  55. For more information,
  56. see {ref}/search-request-script-fields.html[Script Fields].
  57. `scroll_size`::
  58. (unsigned integer) The `size` parameter that is used in {es} searches.
  59. The default value is `1000`.
  60. `delayed_data_check_config`::
  61. (object) Specifies if and with how large a window should the data feed check
  62. for missing data. See <<ml-datafeed-delayed-data-check-config>>.
  63. For more information about these properties,
  64. see <<ml-datafeed-resource>>.
  65. ==== Authorization
  66. If {es} {security-features} are enabled, you must have `manage_ml`, or `manage`
  67. cluster privileges to use this API. For more information, see
  68. {stack-ov}/security-privileges.html[Security Privileges].
  69. ==== Security integration
  70. When {es} {security-features} are enabled, your {dfeed} remembers which roles the
  71. user who created it had at the time of creation and runs the query using those
  72. same roles.
  73. ==== Examples
  74. The following example creates the `datafeed-total-requests` {dfeed}:
  75. [source,js]
  76. --------------------------------------------------
  77. PUT _ml/datafeeds/datafeed-total-requests
  78. {
  79. "job_id": "total-requests",
  80. "indices": ["server-metrics"]
  81. }
  82. --------------------------------------------------
  83. // CONSOLE
  84. // TEST[skip:setup:server_metrics_job]
  85. When the {dfeed} is created, you receive the following results:
  86. [source,js]
  87. ----
  88. {
  89. "datafeed_id": "datafeed-total-requests",
  90. "job_id": "total-requests",
  91. "query_delay": "83474ms",
  92. "indices": [
  93. "server-metrics"
  94. ],
  95. "query": {
  96. "match_all": {
  97. "boost": 1.0
  98. }
  99. },
  100. "scroll_size": 1000,
  101. "chunking_config": {
  102. "mode": "auto"
  103. }
  104. }
  105. ----
  106. // TESTRESPONSE[s/"query_delay": "83474ms"/"query_delay": $body.query_delay/]
  107. // TESTRESPONSE[s/"query.boost": "1.0"/"query.boost": $body.query.boost/]