preview-datafeed.asciidoc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. [role="xpack"]
  2. [[ml-preview-datafeed]]
  3. = Preview {dfeeds} API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Preview {dfeeds}</titleabbrev>
  7. ++++
  8. Previews a {dfeed}.
  9. [[ml-preview-datafeed-request]]
  10. == {api-request-title}
  11. `GET _ml/datafeeds/<datafeed_id>/_preview` +
  12. `POST _ml/datafeeds/<datafeed_id>/_preview` +
  13. `GET _ml/datafeeds/_preview` +
  14. `POST _ml/datafeeds/_preview`
  15. [[ml-preview-datafeed-prereqs]]
  16. == {api-prereq-title}
  17. Requires the following privileges:
  18. * cluster: `manage_ml` (the `machine_learning_admin` built-in role grants this
  19. privilege)
  20. * source index configured in the {dfeed}: `read`.
  21. [[ml-preview-datafeed-desc]]
  22. == {api-description-title}
  23. The preview {dfeeds} API returns the first "page" of search results from a
  24. {dfeed}. You can preview an existing {dfeed} or provide configuration details
  25. for the {dfeed} and {anomaly-job} in the API. The preview shows the structure of
  26. the data that will be passed to the anomaly detection engine.
  27. IMPORTANT: When {es} {security-features} are enabled, the {dfeed} query is
  28. previewed using the credentials of the user calling the preview {dfeed} API.
  29. When the {dfeed} is started it runs the query using the roles of the last user
  30. to create or update it. If the two sets of roles differ then the preview may
  31. not accurately reflect what the {dfeed} will return when started. To avoid
  32. such problems, the same user that creates or updates the {dfeed} should preview
  33. it to ensure it is returning the expected data. Alternatively, use
  34. <<http-clients-secondary-authorization,secondary authorization headers>> to
  35. supply the credentials.
  36. [[ml-preview-datafeed-path-parms]]
  37. == {api-path-parms-title}
  38. `<datafeed_id>`::
  39. (Optional, string)
  40. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=datafeed-id]
  41. +
  42. NOTE: If you provide the `<datafeed_id>` as a path parameter, you cannot
  43. provide {dfeed} or {anomaly-job} configuration details in the request body.
  44. [[ml-preview-datafeed-request-body]]
  45. == {api-request-body-title}
  46. `datafeed_config`::
  47. (Optional, object) The {dfeed} definition to preview. For valid definitions, see
  48. the <<ml-put-datafeed-request-body,create {dfeeds} API>>.
  49. `job_config`::
  50. (Optional, object) The configuration details for the {anomaly-job} that is
  51. associated with the {dfeed}. If the `datafeed_config` object does not include a
  52. `job_id` that references an existing {anomaly-job}, you must supply this
  53. `job_config` object. If you include both a `job_id` and a `job_config`, the
  54. latter information is used. You cannot specify a `job_config` object unless you also supply a `datafeed_config` object. For valid definitions, see the
  55. <<ml-put-job-request-body,create {anomaly-jobs} API>>.
  56. [[ml-preview-datafeed-example]]
  57. == {api-examples-title}
  58. This is an example of providing the ID of an existing {dfeed}:
  59. [source,console]
  60. --------------------------------------------------
  61. GET _ml/datafeeds/datafeed-high_sum_total_sales/_preview
  62. --------------------------------------------------
  63. // TEST[skip:set up Kibana sample data]
  64. The data that is returned for this example is as follows:
  65. [source,console-result]
  66. ----
  67. [
  68. {
  69. "order_date" : 1574294659000,
  70. "category.keyword" : "Men's Clothing",
  71. "customer_full_name.keyword" : "Sultan Al Benson",
  72. "taxful_total_price" : 35.96875
  73. },
  74. {
  75. "order_date" : 1574294918000,
  76. "category.keyword" : [
  77. "Women's Accessories",
  78. "Women's Clothing"
  79. ],
  80. "customer_full_name.keyword" : "Pia Webb",
  81. "taxful_total_price" : 83.0
  82. },
  83. {
  84. "order_date" : 1574295782000,
  85. "category.keyword" : [
  86. "Women's Accessories",
  87. "Women's Shoes"
  88. ],
  89. "customer_full_name.keyword" : "Brigitte Graham",
  90. "taxful_total_price" : 72.0
  91. }
  92. ]
  93. ----
  94. The following example provides {dfeed} and {anomaly-job} configuration
  95. details in the API:
  96. [source,console]
  97. --------------------------------------------------
  98. POST _ml/datafeeds/_preview
  99. {
  100. "datafeed_config": {
  101. "indices" : [
  102. "kibana_sample_data_ecommerce"
  103. ],
  104. "query" : {
  105. "bool" : {
  106. "filter" : [
  107. {
  108. "term" : {
  109. "_index" : "kibana_sample_data_ecommerce"
  110. }
  111. }
  112. ]
  113. }
  114. },
  115. "scroll_size" : 1000
  116. },
  117. "job_config": {
  118. "description" : "Find customers spending an unusually high amount in an hour",
  119. "analysis_config" : {
  120. "bucket_span" : "1h",
  121. "detectors" : [
  122. {
  123. "detector_description" : "High total sales",
  124. "function" : "high_sum",
  125. "field_name" : "taxful_total_price",
  126. "over_field_name" : "customer_full_name.keyword"
  127. }
  128. ],
  129. "influencers" : [
  130. "customer_full_name.keyword",
  131. "category.keyword"
  132. ]
  133. },
  134. "analysis_limits" : {
  135. "model_memory_limit" : "10mb"
  136. },
  137. "data_description" : {
  138. "time_field" : "order_date",
  139. "time_format" : "epoch_ms"
  140. }
  141. }
  142. }
  143. --------------------------------------------------
  144. // TEST[skip:set up Kibana sample data]
  145. The data that is returned for this example is as follows:
  146. [source,console-result]
  147. ----
  148. [
  149. {
  150. "order_date" : 1574294659000,
  151. "category.keyword" : "Men's Clothing",
  152. "customer_full_name.keyword" : "Sultan Al Benson",
  153. "taxful_total_price" : 35.96875
  154. },
  155. {
  156. "order_date" : 1574294918000,
  157. "category.keyword" : [
  158. "Women's Accessories",
  159. "Women's Clothing"
  160. ],
  161. "customer_full_name.keyword" : "Pia Webb",
  162. "taxful_total_price" : 83.0
  163. },
  164. {
  165. "order_date" : 1574295782000,
  166. "category.keyword" : [
  167. "Women's Accessories",
  168. "Women's Shoes"
  169. ],
  170. "customer_full_name.keyword" : "Brigitte Graham",
  171. "taxful_total_price" : 72.0
  172. }
  173. ]
  174. ----