preview-datafeed.asciidoc 5.6 KB

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