get-overall-buckets.asciidoc 6.0 KB

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