Create Snapshot APIedit

Use the Create Snapshot API to create a new snapshot.

Create Snapshot Requestedit

A CreateSnapshotRequest:

CreateSnapshotRequest request = new CreateSnapshotRequest();

Required Argumentsedit

The following arguments are mandatory:


The name of the repository.


The name of the snapshot.

Optional Argumentsedit

The following arguments are optional:

request.indices("test-index0", "test-index1"); 

A list of indices the snapshot is applied to.

request.indicesOptions(IndicesOptions.fromOptions(false, false, true, true)); 

Options applied to the indices.


Set partial to true to allow a successful snapshot without the availability of all the indices primary shards. Defaults to false.


Set includeGlobalState to false to prevent writing the cluster’s global state as part of the snapshot. Defaults to true.


Timeout to connect to the master node as a TimeValue.

Timeout to connect to the master node as a String.


Waits for the snapshot to be completed before a response is returned.

Synchronous Executionedit

Execute a CreateSnapshotRequest synchronously to receive a CreateSnapshotResponse.

CreateSnapshotResponse response = client.snapshot().create(request, RequestOptions.DEFAULT);

Retrieve the SnapshotInfo from a CreateSnapshotResponse when the snapshot is fully created. (The waitForCompletion parameter is true).

SnapshotInfo snapshotInfo = response.getSnapshotInfo(); 

The SnapshotInfo object.

Asynchronous Executionedit

The asynchronous execution of a create snapshot request requires both the CreateSnapshotRequest instance and an ActionListener instance to be passed as arguments to the asynchronous method:

client.snapshot().createAsync(request, RequestOptions.DEFAULT, listener); 

The CreateSnapshotRequest 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 with the onResponse method if the execution is successful or the onFailure method if the execution failed.

A typical listener for CreateSnapshotResponse looks like:

ActionListener<CreateSnapshotResponse> listener =
    new ActionListener<CreateSnapshotResponse>() {
        public void onResponse(CreateSnapshotResponse createSnapshotResponse) {

        public void onFailure(Exception exception) {

Called when the execution is successfully completed. The response is provided as an argument.

Called in case of a failure. The raised exception is provided as an argument.

Snapshot Create Responseedit

Use the CreateSnapshotResponse to retrieve information about the evaluated request:

RestStatus status = response.status(); 

Indicates the node has started the request.