put-datafeed.asciidoc 3.8 KB

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