put-datafeed.asciidoc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 _xpack/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. You must have `manage_ml`, or `manage` cluster privileges to use this API.
  65. For more information, see
  66. {xpack-ref}/security-privileges.html[Security Privileges].
  67. ==== Security Integration
  68. When {security} is enabled, your {dfeed} will remember which roles the user who
  69. created it had at the time of creation, and run the query using those same roles.
  70. ==== Examples
  71. The following example creates the `datafeed-total-requests` {dfeed}:
  72. [source,js]
  73. --------------------------------------------------
  74. PUT _xpack/ml/datafeeds/datafeed-total-requests
  75. {
  76. "job_id": "total-requests",
  77. "indices": ["server-metrics"]
  78. }
  79. --------------------------------------------------
  80. // CONSOLE
  81. // TEST[skip:setup:server_metrics_job]
  82. When the {dfeed} is created, you receive the following results:
  83. [source,js]
  84. ----
  85. {
  86. "datafeed_id": "datafeed-total-requests",
  87. "job_id": "total-requests",
  88. "query_delay": "83474ms",
  89. "indices": [
  90. "server-metrics"
  91. ],
  92. "types": [],
  93. "query": {
  94. "match_all": {
  95. "boost": 1.0
  96. }
  97. },
  98. "scroll_size": 1000,
  99. "chunking_config": {
  100. "mode": "auto"
  101. }
  102. }
  103. ----
  104. // TESTRESPONSE[s/"query_delay": "83474ms"/"query_delay": $body.query_delay/]
  105. // TESTRESPONSE[s/"query.boost": "1.0"/"query.boost": $body.query.boost/]