get-categories.asciidoc 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [[java-rest-high-x-pack-ml-get-categories]]
  2. === Get Categories API
  3. The Get Categories API retrieves one or more category results.
  4. It accepts a `GetCategoriesRequest` object and responds
  5. with a `GetCategoriesResponse` object.
  6. [[java-rest-high-x-pack-ml-get-categories-request]]
  7. ==== Get Categories Request
  8. A `GetCategoriesRequest` 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-categories-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-categories-category-id]
  19. --------------------------------------------------
  20. <1> The id of the category to get. Otherwise it will return all categories.
  21. ["source","java",subs="attributes,callouts,macros"]
  22. --------------------------------------------------
  23. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-categories-page]
  24. --------------------------------------------------
  25. <1> The page parameters `from` and `size`. `from` specifies the number of categories to skip.
  26. `size` specifies the maximum number of categories to get. Defaults to `0` and `100` respectively.
  27. [[java-rest-high-x-pack-ml-get-categories-execution]]
  28. ==== Execution
  29. The request can be executed through the `MachineLearningClient` contained
  30. in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method.
  31. ["source","java",subs="attributes,callouts,macros"]
  32. --------------------------------------------------
  33. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-categories-execute]
  34. --------------------------------------------------
  35. [[java-rest-high-x-pack-ml-get-categories-execution-async]]
  36. ==== Asynchronous Execution
  37. The request can also be executed asynchronously:
  38. ["source","java",subs="attributes,callouts,macros"]
  39. --------------------------------------------------
  40. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-categories-execute-async]
  41. --------------------------------------------------
  42. <1> The `GetCategoriesRequest` to execute and the `ActionListener` to use when
  43. the execution completes
  44. The asynchronous method does not block and returns immediately. Once it is
  45. completed the `ActionListener` is called back with the `onResponse` method
  46. if the execution is successful or the `onFailure` method if the execution
  47. failed.
  48. A typical listener for `GetCategoriesResponse` looks like:
  49. ["source","java",subs="attributes,callouts,macros"]
  50. --------------------------------------------------
  51. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-categories-listener]
  52. --------------------------------------------------
  53. <1> `onResponse` is called back when the action is completed successfully
  54. <2> `onFailure` is called back when some unexpected error occurs
  55. [[java-rest-high-x-pack-ml-get-categories-response]]
  56. ==== Get Categories Response
  57. The returned `GetCategoriesResponse` contains the requested categories:
  58. ["source","java",subs="attributes,callouts,macros"]
  59. --------------------------------------------------
  60. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-categories-response]
  61. --------------------------------------------------
  62. <1> The count of categories that were matched
  63. <2> The categories retrieved