Get Model Snapshots API

The Get Model Snapshots API retrieves one or more model snapshot results. It accepts a GetModelSnapshotsRequest object and responds with a GetModelSnapshotsResponse object.

Get Model Snapshots Request

A GetModelSnapshotsRequest object gets created with an existing non-null jobId.

GetModelSnapshotsRequest request = new GetModelSnapshotsRequest(jobId); 

Constructing a new request referencing an existing jobId

Optional Arguments

The following arguments are optional:

request.setSnapshotId("1541587919"); 

The id of the snapshot to get. Otherwise it will return all snapshots.

request.setDesc(true); 

If true, the snapshots are sorted in descending order. Defaults to false.

request.setEnd("2018-11-07T21:00:00Z"); 

Snapshots with timestamps earlier than this time will be returned.

request.setSort("latest_result_time_stamp"); 

The field to sort snapshots on. Defaults to timestamp.

request.setStart("2018-11-07T00:00:00Z"); 

Snapshots with timestamps on or after this time will be returned.

request.setPageParams(new PageParams(100, 200)); 

The page parameters from and size. from specifies the number of snapshots to skip. size specifies the maximum number of snapshots to retrieve. Defaults to 0 and 100 respectively.

Synchronous Execution

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

GetModelSnapshotsResponse response = client.machineLearning().getModelSnapshots(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 GetModelSnapshotsRequest 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 get-model-snapshots method:

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

The GetModelSnapshotsRequest 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 get-model-snapshots looks like:

ActionListener<GetModelSnapshotsResponse> listener =
    new ActionListener<GetModelSnapshotsResponse>() {
        @Override
        public void onResponse(GetModelSnapshotsResponse getModelSnapshotsResponse) {
            
        }

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

Called when the execution is successfully completed.

Called when the whole GetModelSnapshotsRequest fails.

Get Model Snapshots Response

The returned GetModelSnapshotsResponse contains the requested snapshots:

long count = response.count(); 
List<ModelSnapshot> modelSnapshots = response.snapshots(); 

The count of snapshots that were matched

The snapshots retrieved