get-job.asciidoc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. [[java-rest-high-x-pack-ml-get-job]]
  2. === Get Job API
  3. The Get Job API provides the ability to get {ml} jobs in the cluster.
  4. It accepts a `GetJobRequest` object and responds
  5. with a `GetJobResponse` object.
  6. [[java-rest-high-x-pack-ml-get-job-request]]
  7. ==== Get Job Request
  8. A `GetJobRequest` object gets can have any number of `jobId` or `groupName`
  9. entries. However, they all must be non-null. An empty list is the same as
  10. requesting for all jobs.
  11. ["source","java",subs="attributes,callouts,macros"]
  12. --------------------------------------------------
  13. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-job-request]
  14. --------------------------------------------------
  15. <1> Constructing a new request referencing existing `jobIds`, can contain wildcards
  16. <2> Whether to ignore if a wildcard expression matches no jobs.
  17. (This includes `_all` string or when no jobs have been specified)
  18. [[java-rest-high-x-pack-ml-get-job-execution]]
  19. ==== Execution
  20. The request can be executed through the `MachineLearningClient` contained
  21. in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method.
  22. ["source","java",subs="attributes,callouts,macros"]
  23. --------------------------------------------------
  24. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-job-execute]
  25. --------------------------------------------------
  26. <1> `getCount()` from the `GetJobResponse` indicates the number of jobs found
  27. <2> `getJobs()` is the collection of {ml} `Job` objects found
  28. [[java-rest-high-x-pack-ml-get-job-execution-async]]
  29. ==== Asynchronous Execution
  30. The request can also be executed asynchronously:
  31. ["source","java",subs="attributes,callouts,macros"]
  32. --------------------------------------------------
  33. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-job-execute-async]
  34. --------------------------------------------------
  35. <1> The `GetJobRequest` to execute and the `ActionListener` to use when
  36. the execution completes
  37. The method does not block and returns immediately. The passed `ActionListener` is used
  38. to notify the caller of completion. A typical `ActionListener` for `GetJobResponse` may
  39. look like
  40. ["source","java",subs="attributes,callouts,macros"]
  41. --------------------------------------------------
  42. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-job-listener]
  43. --------------------------------------------------
  44. <1> `onResponse` is called back when the action is completed successfully
  45. <2> `onFailure` is called back when some unexpected error occurs