[[java-rest-high-x-pack-ml-update-job]] === Update Job API The Update Job API provides the ability to update a {ml} job. It accepts a `UpdateJobRequest` object and responds with a `PutJobResponse` object. [[java-rest-high-x-pack-ml-update-job-request]] ==== Update Job Request An `UpdateJobRequest` object gets created with a `JobUpdate` object. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-update-job-request] -------------------------------------------------- <1> Constructing a new request referencing a `JobUpdate` object ==== Optional Arguments The `JobUpdate` object has many optional arguments with which to update an existing {ml} job. An existing, non-null `jobId` must be referenced in its creation. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-update-job-options] -------------------------------------------------- <1> Mandatory, non-null `jobId` referencing an existing {ml} job <2> Updated description <3> Updated analysis limits <4> Updated background persistence interval <5> Updated analysis config's categorization filters <6> Updated detectors through the `JobUpdate.DetectorUpdate` object <7> Updated group membership <8> Updated result retention <9> Updated model plot configuration <10> Updated model snapshot retention setting <11> Updated custom settings <12> Updated renormalization window Included with these options are specific optional `JobUpdate.DetectorUpdate` updates. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-update-job-detector-options] -------------------------------------------------- <1> The index of the detector. `O` means unknown <2> The optional description of the detector <3> The `DetectionRule` rules that apply to this detector [[java-rest-high-x-pack-ml-update-job-execution]] ==== Execution The request can be executed through the `MachineLearningClient` contained in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-update-job-execute] -------------------------------------------------- [[java-rest-high-x-pack-ml-update-job-execution-async]] ==== Asynchronous Execution The request can also be executed asynchronously: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-update-job-execute-async] -------------------------------------------------- <1> The `UpdateJobRequest` to execute and the `ActionListener` to use when the execution completes The method does not block and returns immediately. The passed `ActionListener` is used to notify the caller of completion. A typical `ActionListener` for `PutJobResponse` may look like ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-update-job-listener] -------------------------------------------------- <1> `onResponse` is called back when the action is completed successfully <2> `onFailure` is called back when some unexpected error occurs [[java-rest-high-x-pack-ml-update-job-response]] ==== Update Job Response A `PutJobResponse` contains the updated `Job` object ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-update-job-response] -------------------------------------------------- <1> `getResponse()` returns the updated `Job` object