get-bucket.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[ml-get-bucket]]
  4. === Get buckets API
  5. ++++
  6. <titleabbrev>Get buckets</titleabbrev>
  7. ++++
  8. Retrieves {anomaly-job} results for one or more buckets.
  9. [[ml-get-bucket-request]]
  10. ==== {api-request-title}
  11. `GET _ml/anomaly_detectors/<job_id>/results/buckets` +
  12. `GET _ml/anomaly_detectors/<job_id>/results/buckets/<timestamp>`
  13. [[ml-get-bucket-prereqs]]
  14. ==== {api-prereq-title}
  15. * If the {es} {security-features} are enabled, you must have `monitor_ml`,
  16. `monitor`, `manage_ml`, or `manage` cluster privileges to use this API. You also
  17. need `read` index privilege on the index that stores the results. The
  18. `machine_learning_admin` and `machine_learning_user` roles provide these
  19. privileges. For more information, see
  20. <<security-privileges>> and
  21. <<built-in-roles>>.
  22. [[ml-get-bucket-desc]]
  23. ==== {api-description-title}
  24. The get buckets API presents a chronological view of the records, grouped by
  25. bucket.
  26. [[ml-get-bucket-path-parms]]
  27. ==== {api-path-parms-title}
  28. `<job_id>`::
  29. (Required, string)
  30. include::{docdir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]
  31. `<timestamp>`::
  32. (Optional, string) The timestamp of a single bucket result. If you do not
  33. specify this parameter, the API returns information about all buckets.
  34. [[ml-get-bucket-request-body]]
  35. ==== {api-request-body-title}
  36. `anomaly_score`::
  37. (Optional, double) Returns buckets with anomaly scores greater or equal than
  38. this value.
  39. `desc`::
  40. (Optional, boolean) If true, the buckets are sorted in descending order.
  41. `end`::
  42. (Optional, string) Returns buckets with timestamps earlier than this time.
  43. `exclude_interim`::
  44. (Optional, boolean)
  45. include::{docdir}/ml/ml-shared.asciidoc[tag=exclude-interim-results]
  46. `expand`::
  47. (Optional, boolean) If true, the output includes anomaly records.
  48. `page`::
  49. `page`.`from`:::
  50. (Optional, integer) Skips the specified number of buckets.
  51. `page`.`size`:::
  52. (Optional, integer) Specifies the maximum number of buckets to obtain.
  53. `sort`::
  54. (Optional, string) Specifies the sort field for the requested buckets. By
  55. default, the buckets are sorted by the `timestamp` field.
  56. `start`::
  57. (Optional, string) Returns buckets with timestamps after this time.
  58. [[ml-get-bucket-results]]
  59. ==== {api-response-body-title}
  60. The API returns an array of bucket objects, which have the following properties:
  61. `anomaly_score`::
  62. (number) The maximum anomaly score, between 0-100, for any of the bucket
  63. influencers. This is an overall, rate-limited score for the job. All the anomaly
  64. records in the bucket contribute to this score. This value might be updated as
  65. new data is analyzed.
  66. `bucket_influencers`::
  67. (array) An array of bucket influencer objects, which have the following
  68. properties:
  69. `bucket_influencers`.`anomaly_score`:::
  70. (number) A normalized score between 0-100, which is calculated for each bucket
  71. influencer. This score might be updated as newer data is analyzed.
  72. `bucket_influencers`.`bucket_span`:::
  73. (number) The length of the bucket in seconds. This value matches the `bucket_span`
  74. that is specified in the job.
  75. `bucket_influencers`.`initial_anomaly_score`:::
  76. (number) The score between 0-100 for each bucket influencer. This score is the
  77. initial value that was calculated at the time the bucket was processed.
  78. `bucket_influencers`.`influencer_field_name`:::
  79. (string) The field name of the influencer.
  80. `bucket_influencers`.`influencer_field_value`:::
  81. (string) The field value of the influencer.
  82. `bucket_influencers`.`is_interim`:::
  83. (boolean)
  84. include::{docdir}/ml/ml-shared.asciidoc[tag=is-interim]
  85. `bucket_influencers`.`job_id`:::
  86. (string)
  87. include::{docdir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]
  88. `bucket_influencers`.`probability`:::
  89. (number) The probability that the bucket has this behavior, in the range 0 to 1.
  90. This value can be held to a high precision of over 300 decimal places, so the
  91. `anomaly_score` is provided as a human-readable and friendly interpretation of
  92. this.
  93. `bucket_influencers`.`raw_anomaly_score`:::
  94. (number) Internal.
  95. `bucket_influencers`.`result_type`:::
  96. (string) Internal. This value is always set to `bucket_influencer`.
  97. `bucket_influencers`.`timestamp`:::
  98. (date) The start time of the bucket for which these results were calculated.
  99. `bucket_span`::
  100. (number)
  101. include::{docdir}/ml/ml-shared.asciidoc[tag=bucket-span-results]
  102. `event_count`::
  103. (number) The number of input data records processed in this bucket.
  104. `initial_anomaly_score`::
  105. (number) The maximum `anomaly_score` for any of the bucket influencers. This is
  106. the initial value that was calculated at the time the bucket was processed.
  107. `is_interim`::
  108. (boolean)
  109. include::{docdir}/ml/ml-shared.asciidoc[tag=is-interim]
  110. `job_id`::
  111. (string)
  112. include::{docdir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]
  113. `processing_time_ms`::
  114. (number) The amount of time, in milliseconds, that it took to analyze the
  115. bucket contents and calculate results.
  116. `result_type`::
  117. (string) Internal. This value is always set to `bucket`.
  118. `timestamp`::
  119. (date) The start time of the bucket. This timestamp uniquely identifies the
  120. bucket.
  121. +
  122. --
  123. NOTE: Events that occur exactly at the timestamp of the bucket are included in
  124. the results for the bucket.
  125. --
  126. [[ml-get-bucket-example]]
  127. ==== {api-examples-title}
  128. The following example gets bucket information for the `it-ops-kpi` job:
  129. [source,console]
  130. --------------------------------------------------
  131. GET _ml/anomaly_detectors/it-ops-kpi/results/buckets
  132. {
  133. "anomaly_score": 80,
  134. "start": "1454530200001"
  135. }
  136. --------------------------------------------------
  137. // TEST[skip:todo]
  138. In this example, the API returns a single result that matches the specified
  139. score and time constraints:
  140. [source,js]
  141. ----
  142. {
  143. "count": 1,
  144. "buckets": [
  145. {
  146. "job_id": "it-ops-kpi",
  147. "timestamp": 1454943900000,
  148. "anomaly_score": 94.1706,
  149. "bucket_span": 300,
  150. "initial_anomaly_score": 94.1706,
  151. "event_count": 153,
  152. "is_interim": false,
  153. "bucket_influencers": [
  154. {
  155. "job_id": "it-ops-kpi",
  156. "result_type": "bucket_influencer",
  157. "influencer_field_name": "bucket_time",
  158. "initial_anomaly_score": 94.1706,
  159. "anomaly_score": 94.1706,
  160. "raw_anomaly_score": 2.32119,
  161. "probability": 0.00000575042,
  162. "timestamp": 1454943900000,
  163. "bucket_span": 300,
  164. "is_interim": false
  165. }
  166. ],
  167. "processing_time_ms": 2,
  168. "partition_scores": [],
  169. "result_type": "bucket"
  170. }
  171. ]
  172. }
  173. ----