Update Job API

edit

The Update Job API provides the ability to update a machine learning job. It accepts a UpdateJobRequest object and responds with a PutJobResponse object.

Update Job Request

edit

An UpdateJobRequest object gets created with a JobUpdate object.

UpdateJobRequest updateJobRequest = new UpdateJobRequest(update); 

Constructing a new request referencing a JobUpdate object

Optional Arguments

edit

The JobUpdate object has many optional arguments with which to update an existing machine learning job. An existing, non-null jobId must be referenced in its creation.

JobUpdate update = new JobUpdate.Builder(jobId) 
    .setDescription("My description") 
    .setAnalysisLimits(new AnalysisLimits(1000L, null)) 
    .setBackgroundPersistInterval(TimeValue.timeValueHours(3)) 
    .setCategorizationFilters(Arrays.asList("categorization-filter")) 
    .setDetectorUpdates(Arrays.asList(detectorUpdate)) 
    .setGroups(Arrays.asList("job-group-1")) 
    .setResultsRetentionDays(10L) 
    .setModelPlotConfig(new ModelPlotConfig(true, null)) 
    .setModelSnapshotRetentionDays(7L) 
    .setCustomSettings(customSettings) 
    .setRenormalizationWindowDays(3L) 
    .build();

Mandatory, non-null jobId referencing an existing machine learning job

Updated description

Updated analysis limits

Updated background persistence interval

Updated analysis config’s categorization filters

Updated detectors through the JobUpdate.DetectorUpdate object

Updated group membership

Updated result retention

Updated model plot configuration

Updated model snapshot retention setting

Updated custom settings

Updated renormalization window

Included with these options are specific optional JobUpdate.DetectorUpdate updates.

JobUpdate.DetectorUpdate detectorUpdate = new JobUpdate.DetectorUpdate(0, 
    "detector description", 
    detectionRules); 

The index of the detector. O means unknown

The optional description of the detector

The DetectionRule rules that apply to this detector

Synchronous Execution

edit

When executing a UpdateJobRequest in the following manner, the client waits for the PutJobResponse to be returned before continuing with code execution:

PutJobResponse updateJobResponse = client.machineLearning().updateJob(updateJobRequest, RequestOptions.DEFAULT);

Asynchronous Execution

edit

Executing a UpdateJobRequest can also be done in an asynchronous fashion so that the client can return directly. Users need to specify how the response or potential failures will be handled by passing the request and a listener to the asynchronous update-job method:

client.machineLearning().updateJobAsync(updateJobRequest, RequestOptions.DEFAULT, listener); 

The UpdateJobRequest to execute and the ActionListener to use when the execution completes

The asynchronous method does not block and returns immediately. Once it is completed the ActionListener is called back using the onResponse method if the execution successfully completed or using the onFailure method if it failed.

A typical listener for update-job looks like:

ActionListener<PutJobResponse> listener = new ActionListener<PutJobResponse>() {
    @Override
    public void onResponse(PutJobResponse updateJobResponse) {
        
    }

    @Override
    public void onFailure(Exception e) {
        
    }
};

Called when the execution is successfully completed.

Called when the whole UpdateJobRequest fails.

Update Job Response

edit

A PutJobResponse contains the updated Job object

Job updatedJob = updateJobResponse.getResponse(); 

getResponse() returns the updated Job object