put-datafeed.asciidoc 3.9 KB

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