get-overall-buckets.asciidoc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[ml-get-overall-buckets]]
  4. = Get overall buckets API
  5. ++++
  6. <titleabbrev>Get overall buckets</titleabbrev>
  7. ++++
  8. Retrieves overall bucket results that summarize the bucket results of multiple
  9. {anomaly-jobs}.
  10. [[ml-get-overall-buckets-request]]
  11. == {api-request-title}
  12. `GET _ml/anomaly_detectors/<job_id>/results/overall_buckets` +
  13. `GET _ml/anomaly_detectors/<job_id>,<job_id>/results/overall_buckets` +
  14. `GET _ml/anomaly_detectors/_all/results/overall_buckets`
  15. [[ml-get-overall-buckets-prereqs]]
  16. == {api-prereq-title}
  17. * If the {es} {security-features} are enabled, you must have `monitor_ml`,
  18. `monitor`, `manage_ml`, or `manage` cluster privileges to use this API. You also
  19. need `read` index privilege on the index that stores the results. The
  20. `machine_learning_admin` and `machine_learning_user` roles provide these
  21. privileges. See <<security-privileges>>, <<built-in-roles>>, and
  22. {ml-docs-setup-privileges}.
  23. [[ml-get-overall-buckets-desc]]
  24. == {api-description-title}
  25. You can summarize the bucket results for all {anomaly-jobs} by using `_all` or
  26. by specifying `*` as the `<job_id>`.
  27. By default, an overall bucket has a span equal to the largest bucket span of the
  28. specified {anomaly-jobs}. To override that behavior, use the optional
  29. `bucket_span` parameter. To learn more about the concept of buckets, see
  30. {ml-docs}/ml-buckets.html[Buckets].
  31. The `overall_score` is calculated by combining the scores of all the buckets
  32. within the overall bucket span. First, the maximum `anomaly_score` per
  33. {anomaly-job} in the overall bucket is calculated. Then the `top_n` of those
  34. scores are averaged to result in the `overall_score`. This means that you can
  35. fine-tune the `overall_score` so that it is more or less sensitive to the number
  36. of jobs that detect an anomaly at the same time. For example, if you set `top_n`
  37. to `1`, the `overall_score` is the maximum bucket score in the overall bucket.
  38. Alternatively, if you set `top_n` to the number of jobs, the `overall_score` is
  39. high only when all jobs detect anomalies in that overall bucket. If you set
  40. the `bucket_span` parameter (to a value greater than its default), the
  41. `overall_score` is the maximum `overall_score` of the overall buckets that have
  42. a span equal to the jobs' largest bucket span.
  43. [[ml-get-overall-buckets-path-parms]]
  44. == {api-path-parms-title}
  45. `<job_id>`::
  46. (Required, string)
  47. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection-wildcard-list]
  48. [[ml-get-overall-buckets-request-body]]
  49. == {api-request-body-title}
  50. `allow_no_match`::
  51. (Optional, Boolean)
  52. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-jobs]
  53. `bucket_span`::
  54. (Optional, string) The span of the overall buckets. Must be greater or equal to
  55. the largest bucket span of the specified {anomaly-jobs}, which is the default
  56. value.
  57. `end`::
  58. (Optional, string) Returns overall buckets with timestamps earlier than this
  59. time.
  60. `exclude_interim`::
  61. (Optional, Boolean) If `true`, the output excludes interim overall buckets.
  62. Overall buckets are interim if any of the job buckets within the overall bucket
  63. interval are interim. By default, interim results are included.
  64. `overall_score`::
  65. (Optional, double) Returns overall buckets with overall scores greater or equal
  66. than this value.
  67. `start`::
  68. (Optional, string) Returns overall buckets with timestamps after this time.
  69. `top_n`::
  70. (Optional, integer) The number of top {anomaly-job} bucket scores to be used in
  71. the `overall_score` calculation. The default value is `1`.
  72. [[ml-get-overall-buckets-results]]
  73. == {api-response-body-title}
  74. The API returns an array of overall bucket objects, which have the following
  75. properties:
  76. `bucket_span`::
  77. (number) The length of the bucket in seconds. Matches the `bucket_span`
  78. of the job with the longest one.
  79. `is_interim`::
  80. (Boolean)
  81. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=is-interim]
  82. `jobs`::
  83. (array) An array of objects that contain the `max_anomaly_score` per `job_id`.
  84. `overall_score`::
  85. (number) The `top_n` average of the max bucket `anomaly_score` per job.
  86. `result_type`::
  87. (string) Internal. This is always set to `overall_bucket`.
  88. `timestamp`::
  89. (date)
  90. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=timestamp-results]
  91. [[ml-get-overall-buckets-example]]
  92. == {api-examples-title}
  93. [source,console]
  94. --------------------------------------------------
  95. GET _ml/anomaly_detectors/job-*/results/overall_buckets
  96. {
  97. "overall_score": 80,
  98. "start": "1403532000000"
  99. }
  100. --------------------------------------------------
  101. // TEST[skip:todo]
  102. In this example, the API returns a single result that matches the specified
  103. score and time constraints. The `overall_score` is the max job score as
  104. `top_n` defaults to 1 when not specified:
  105. [source,js]
  106. ----
  107. {
  108. "count": 1,
  109. "overall_buckets": [
  110. {
  111. "timestamp" : 1403532000000,
  112. "bucket_span" : 3600,
  113. "overall_score" : 80.0,
  114. "jobs" : [
  115. {
  116. "job_id" : "job-1",
  117. "max_anomaly_score" : 30.0
  118. },
  119. {
  120. "job_id" : "job-2",
  121. "max_anomaly_score" : 10.0
  122. },
  123. {
  124. "job_id" : "job-3",
  125. "max_anomaly_score" : 80.0
  126. }
  127. ],
  128. "is_interim" : false,
  129. "result_type" : "overall_bucket"
  130. }
  131. ]
  132. }
  133. ----
  134. The next example is similar but this time `top_n` is set to `2`:
  135. [source,console]
  136. --------------------------------------------------
  137. GET _ml/anomaly_detectors/job-*/results/overall_buckets
  138. {
  139. "top_n": 2,
  140. "overall_score": 50.0,
  141. "start": "1403532000000"
  142. }
  143. --------------------------------------------------
  144. // TEST[skip:todo]
  145. Note how the `overall_score` is now the average of the top 2 job scores:
  146. [source,js]
  147. ----
  148. {
  149. "count": 1,
  150. "overall_buckets": [
  151. {
  152. "timestamp" : 1403532000000,
  153. "bucket_span" : 3600,
  154. "overall_score" : 55.0,
  155. "jobs" : [
  156. {
  157. "job_id" : "job-1",
  158. "max_anomaly_score" : 30.0
  159. },
  160. {
  161. "job_id" : "job-2",
  162. "max_anomaly_score" : 10.0
  163. },
  164. {
  165. "job_id" : "job-3",
  166. "max_anomaly_score" : 80.0
  167. }
  168. ],
  169. "is_interim" : false,
  170. "result_type" : "overall_bucket"
  171. }
  172. ]
  173. }
  174. ----