Update Model Snapshot API

The Update Model Snapshot API provides the ability to update a machine learning model snapshot. It accepts a UpdateModelSnapshotRequest object and responds with a UpdateModelSnapshotResponse object.

Update Model Snapshot Request

A UpdateModelSnapshotRequest requires the following arguments:

UpdateModelSnapshotRequest request = new UpdateModelSnapshotRequest(jobId, snapshotId); 

Constructing a new request referencing existing jobId and snapshotId values.

Optional Arguments

The following arguments are optional:

request.setDescription("My Snapshot"); 

The updated description of the machine learning model snapshot

request.setRetain(true); 

The updated retain property of the machine learning model snapshot

Synchronous Execution

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

UpdateModelSnapshotResponse response = client.machineLearning().updateModelSnapshot(request, RequestOptions.DEFAULT);

Synchronous calls may throw an IOException in case of either failing to parse the REST response in the high-level REST client, the request times out or similar cases where there is no response coming back from the server.

In cases where the server returns a 4xx or 5xx error code, the high-level client tries to parse the response body error details instead and then throws a generic ElasticsearchException and adds the original ResponseException as a suppressed exception to it.

Asynchronous Execution

Executing a UpdateModelSnapshotRequest 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-model-snapshot method:

client.machineLearning().updateModelSnapshotAsync(request, RequestOptions.DEFAULT, listener); 

The UpdateModelSnapshotRequest 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. Failure scenarios and expected exceptions are the same as in the synchronous execution case.

A typical listener for update-model-snapshot looks like:

ActionListener<UpdateModelSnapshotResponse> listener =
    new ActionListener<UpdateModelSnapshotResponse>() {
        @Override
        public void onResponse(UpdateModelSnapshotResponse updateModelSnapshotResponse) {
            
        }

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

Called when the execution is successfully completed.

Called when the whole UpdateModelSnapshotRequest fails.

Update Job Response

A UpdateModelSnapshotResponse contains an acknowledgement of the update request and the full representation of the updated ModelSnapshot object

boolean acknowledged = response.getAcknowledged(); 
ModelSnapshot modelSnapshot = response.getModel(); 

An acknowledgement of the request

The updated ModelSnapshot