get-calendars.asciidoc 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [[java-rest-high-x-pack-ml-get-calendars]]
  2. === Get Calendars API
  3. Retrieves one or more calendar objects.
  4. It accepts a `GetCalendarsRequest` and responds
  5. with a `GetCalendarsResponse` object.
  6. [[java-rest-high-x-pack-ml-get-calendars-request]]
  7. ==== Get Calendars Request
  8. By default a `GetCalendarsRequest` with no calendar Id set will return all
  9. calendars. Using the literal `_all` also returns all calendars.
  10. ["source","java",subs="attributes,callouts,macros"]
  11. --------------------------------------------------
  12. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-calendars-request]
  13. --------------------------------------------------
  14. <1> Constructing a new request for all calendars
  15. ==== Optional Arguments
  16. The following arguments are optional:
  17. ["source","java",subs="attributes,callouts,macros"]
  18. --------------------------------------------------
  19. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-calendars-id]
  20. --------------------------------------------------
  21. <1> Construct a request for the single calendar `holidays`
  22. ["source","java",subs="attributes,callouts,macros"]
  23. --------------------------------------------------
  24. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-calendars-page]
  25. --------------------------------------------------
  26. <1> The page parameters `from` and `size`. `from` specifies the number of calendars to skip.
  27. `size` specifies the maximum number of calendars to get. Defaults to `0` and `100` respectively.
  28. [[java-rest-high-x-pack-ml-get-calendars-execution]]
  29. ==== Execution
  30. The request can be executed through the `MachineLearningClient` contained
  31. in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method.
  32. ["source","java",subs="attributes,callouts,macros"]
  33. --------------------------------------------------
  34. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-calendars-execution]
  35. --------------------------------------------------
  36. [[java-rest-high-x-pack-ml-get-calendars-execution-async]]
  37. ==== Asynchronous Execution
  38. The request can also be executed asynchronously:
  39. ["source","java",subs="attributes,callouts,macros"]
  40. --------------------------------------------------
  41. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-calendars-execute-async]
  42. --------------------------------------------------
  43. <1> The `GetCalendarsRequest` to execute and the `ActionListener` to use when
  44. the execution completes
  45. The asynchronous method does not block and returns immediately. Once it is
  46. completed the `ActionListener` is called back with the `onResponse` method
  47. if the execution is successful or the `onFailure` method if the execution
  48. failed.
  49. A typical listener for `GetCalendarsResponse` looks like:
  50. ["source","java",subs="attributes,callouts,macros"]
  51. --------------------------------------------------
  52. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-calendars-listener]
  53. --------------------------------------------------
  54. <1> `onResponse` is called back when the action is completed successfully
  55. <2> `onFailure` is called back when some unexpected error occurs
  56. [[java-rest-high-x-pack-ml-get-calendars-response]]
  57. ==== Get calendars Response
  58. The returned `GetCalendarsResponse` contains the requested calendars:
  59. ["source","java",subs="attributes,callouts,macros"]
  60. --------------------------------------------------
  61. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-calendars-response]
  62. --------------------------------------------------
  63. <1> The count of calendars that were matched
  64. <2> The calendars retrieved