get-buckets.asciidoc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. [[java-rest-high-x-pack-ml-get-buckets]]
  2. === Get Buckets API
  3. The Get Buckets API retrieves one or more bucket results.
  4. It accepts a `GetBucketsRequest` object and responds
  5. with a `GetBucketsResponse` object.
  6. [[java-rest-high-x-pack-ml-get-buckets-request]]
  7. ==== Get Buckets Request
  8. A `GetBucketsRequest` object gets created with an existing non-null `jobId`.
  9. ["source","java",subs="attributes,callouts,macros"]
  10. --------------------------------------------------
  11. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-request]
  12. --------------------------------------------------
  13. <1> Constructing a new request referencing an existing `jobId`
  14. ==== Optional Arguments
  15. The following arguments are optional:
  16. ["source","java",subs="attributes,callouts,macros"]
  17. --------------------------------------------------
  18. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-timestamp]
  19. --------------------------------------------------
  20. <1> The timestamp of the bucket to get. Otherwise it will return all buckets.
  21. ["source","java",subs="attributes,callouts,macros"]
  22. --------------------------------------------------
  23. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-anomaly-score]
  24. --------------------------------------------------
  25. <1> Buckets with anomaly scores greater or equal than this value will be returned.
  26. ["source","java",subs="attributes,callouts,macros"]
  27. --------------------------------------------------
  28. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-desc]
  29. --------------------------------------------------
  30. <1> If `true`, the buckets are sorted in descending order. Defaults to `false`.
  31. ["source","java",subs="attributes,callouts,macros"]
  32. --------------------------------------------------
  33. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-end]
  34. --------------------------------------------------
  35. <1> Buckets with timestamps earlier than this time will be returned.
  36. ["source","java",subs="attributes,callouts,macros"]
  37. --------------------------------------------------
  38. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-exclude-interim]
  39. --------------------------------------------------
  40. <1> If `true`, interim results will be excluded. Defaults to `false`.
  41. ["source","java",subs="attributes,callouts,macros"]
  42. --------------------------------------------------
  43. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-expand]
  44. --------------------------------------------------
  45. <1> If `true`, buckets will include their anomaly records. Defaults to `false`.
  46. ["source","java",subs="attributes,callouts,macros"]
  47. --------------------------------------------------
  48. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-page]
  49. --------------------------------------------------
  50. <1> The page parameters `from` and `size`. `from` specifies the number of buckets to skip.
  51. `size` specifies the maximum number of buckets to get. Defaults to `0` and `100` respectively.
  52. ["source","java",subs="attributes,callouts,macros"]
  53. --------------------------------------------------
  54. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-sort]
  55. --------------------------------------------------
  56. <1> The field to sort buckets on. Defaults to `timestamp`.
  57. ["source","java",subs="attributes,callouts,macros"]
  58. --------------------------------------------------
  59. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-end]
  60. --------------------------------------------------
  61. <1> Buckets with timestamps on or after this time will be returned.
  62. [[java-rest-high-x-pack-ml-get-buckets-execution]]
  63. ==== Execution
  64. The request can be executed through the `MachineLearningClient` contained
  65. in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method.
  66. ["source","java",subs="attributes,callouts,macros"]
  67. --------------------------------------------------
  68. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-execute]
  69. --------------------------------------------------
  70. [[java-rest-high-x-pack-ml-get-buckets-execution-async]]
  71. ==== Asynchronous Execution
  72. The request can also be executed asynchronously:
  73. ["source","java",subs="attributes,callouts,macros"]
  74. --------------------------------------------------
  75. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-execute-async]
  76. --------------------------------------------------
  77. <1> The `GetBucketsRequest` to execute and the `ActionListener` to use when
  78. the execution completes
  79. The asynchronous method does not block and returns immediately. Once it is
  80. completed the `ActionListener` is called back with the `onResponse` method
  81. if the execution is successful or the `onFailure` method if the execution
  82. failed.
  83. A typical listener for `GetBucketsResponse` looks like:
  84. ["source","java",subs="attributes,callouts,macros"]
  85. --------------------------------------------------
  86. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-listener]
  87. --------------------------------------------------
  88. <1> `onResponse` is called back when the action is completed successfully
  89. <2> `onFailure` is called back when some unexpected error occurs
  90. [[java-rest-high-snapshot-ml-get-buckets-response]]
  91. ==== Get Buckets Response
  92. The returned `GetBucketsResponse` contains the requested buckets:
  93. ["source","java",subs="attributes,callouts,macros"]
  94. --------------------------------------------------
  95. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-buckets-response]
  96. --------------------------------------------------
  97. <1> The count of buckets that were matched
  98. <2> The buckets retrieved