get-overall-buckets.asciidoc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 {stack-ov}/security-privileges.html[Security privileges] and
  22. {stack-ov}/built-in-roles.html[Built-in roles].
  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. {stack-ov}/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) Identifier for the {anomaly-job}. It can be a job
  47. identifier, a group name, a comma-separated list of jobs or groups, or a
  48. wildcard expression.
  49. [[ml-get-overall-buckets-request-body]]
  50. ==== {api-request-body-title}
  51. `allow_no_jobs`::
  52. (Optional, boolean) If `false` and the `job_id` does not match any
  53. {anomaly-jobs}, an error occurs. The default value is `true`.
  54. `bucket_span`::
  55. (Optional, string) The span of the overall buckets. Must be greater or equal
  56. to the largest bucket span of the specified {anomaly-jobs}, which is the
  57. default value.
  58. `end`::
  59. (Optional, string) Returns overall buckets with timestamps earlier than this
  60. time.
  61. `exclude_interim`::
  62. (Optional, boolean) If `true`, the output excludes interim overall buckets.
  63. Overall buckets are interim if any of the job buckets within the overall
  64. bucket interval are interim. By default, interim results are included.
  65. `overall_score`::
  66. (Optional, double) Returns overall buckets with overall scores greater or
  67. equal than this value.
  68. `start`::
  69. (Optional, string) Returns overall buckets with timestamps after this time.
  70. `top_n`::
  71. (Optional, integer) The number of top {anomaly-job} bucket scores to be used
  72. in the `overall_score` calculation. The default value is `1`.
  73. [[ml-get-overall-buckets-results]]
  74. ==== {api-response-body-title}
  75. The API returns the following information:
  76. `overall_buckets`::
  77. (array) An array of overall bucket objects. For more information, see
  78. <<ml-results-overall-buckets,Overall Buckets>>.
  79. [[ml-get-overall-buckets-example]]
  80. ==== {api-examples-title}
  81. The following example gets overall buckets for {anomaly-jobs} with IDs matching
  82. `job-*`:
  83. [source,console]
  84. --------------------------------------------------
  85. GET _ml/anomaly_detectors/job-*/results/overall_buckets
  86. {
  87. "overall_score": 80,
  88. "start": "1403532000000"
  89. }
  90. --------------------------------------------------
  91. // TEST[skip:todo]
  92. In this example, the API returns a single result that matches the specified
  93. score and time constraints. The `overall_score` is the max job score as
  94. `top_n` defaults to 1 when not specified:
  95. [source,js]
  96. ----
  97. {
  98. "count": 1,
  99. "overall_buckets": [
  100. {
  101. "timestamp" : 1403532000000,
  102. "bucket_span" : 3600,
  103. "overall_score" : 80.0,
  104. "jobs" : [
  105. {
  106. "job_id" : "job-1",
  107. "max_anomaly_score" : 30.0
  108. },
  109. {
  110. "job_id" : "job-2",
  111. "max_anomaly_score" : 10.0
  112. },
  113. {
  114. "job_id" : "job-3",
  115. "max_anomaly_score" : 80.0
  116. }
  117. ],
  118. "is_interim" : false,
  119. "result_type" : "overall_bucket"
  120. }
  121. ]
  122. }
  123. ----
  124. The next example is similar but this time `top_n` is set to `2`:
  125. [source,console]
  126. --------------------------------------------------
  127. GET _ml/anomaly_detectors/job-*/results/overall_buckets
  128. {
  129. "top_n": 2,
  130. "overall_score": 50.0,
  131. "start": "1403532000000"
  132. }
  133. --------------------------------------------------
  134. // TEST[skip:todo]
  135. Note how the `overall_score` is now the average of the top 2 job scores:
  136. [source,js]
  137. ----
  138. {
  139. "count": 1,
  140. "overall_buckets": [
  141. {
  142. "timestamp" : 1403532000000,
  143. "bucket_span" : 3600,
  144. "overall_score" : 55.0,
  145. "jobs" : [
  146. {
  147. "job_id" : "job-1",
  148. "max_anomaly_score" : 30.0
  149. },
  150. {
  151. "job_id" : "job-2",
  152. "max_anomaly_score" : 10.0
  153. },
  154. {
  155. "job_id" : "job-3",
  156. "max_anomaly_score" : 80.0
  157. }
  158. ],
  159. "is_interim" : false,
  160. "result_type" : "overall_bucket"
  161. }
  162. ]
  163. }
  164. ----