put-datafeed.asciidoc 4.0 KB

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