Snapshot Create RepositoryAPIedit

The Snapshot Create RepositoryAPI allows to register a snapshot repository.

Snapshot Create RepositoryRequestedit

A PutRepositoryRequest:

PutRepositoryRequest request = new PutRepositoryRequest();

Repository Settingsedit

Settings requirements will differ based on the repository backend chosen.


Sets the repository settings

Providing the Settingsedit

The settings to be applied can be provided in different ways:

String locationKey = FsRepository.LOCATION_SETTING.getKey();
String locationValue = ".";
String compressKey = FsRepository.COMPRESS_SETTING.getKey();
boolean compressValue = true;

Settings settings = Settings.builder()
    .put(locationKey, locationValue)
    .put(compressKey, compressValue)

Settings provided as Settings

Settings.Builder settingsBuilder = Settings.builder()
    .put(locationKey, locationValue)
    .put(compressKey, compressValue);

Settings provided as Settings.Builder

request.settings("{\"location\": \".\", \"compress\": \"true\"}",

Settings provided as String

Map<String, Object> map = new HashMap<>();
map.put(locationKey, locationValue);
map.put(compressKey, compressValue);

Settings provided as a Map

Required Argumentsedit

The following arguments must be provided:; 

The name of the repository


The type of the repository

Optional Argumentsedit

The following arguments can optionally be provided:


Timeout to wait for the all the nodes to acknowledge the settings were applied as a TimeValue

Timeout to wait for the all the nodes to acknowledge the settings were applied as a String


Timeout to connect to the master node as a TimeValue

Timeout to connect to the master node as a String


Verify after creation as a Boolean

Synchronous Executionedit

AcknowledgedResponse response = client.snapshot().createRepository(request, RequestOptions.DEFAULT);

Asynchronous Executionedit

The asynchronous execution of a repository put settings requires both the PutRepositoryRequest instance and an ActionListener instance to be passed to the asynchronous method:

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

The PutRepositoryRequest 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 PutRepositoryResponse looks like:

ActionListener<AcknowledgedResponse> listener =
    new ActionListener<AcknowledgedResponse>() {
        public void onResponse(AcknowledgedResponse putRepositoryResponse) {

        public void onFailure(Exception e) {

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 RepositoryResponseedit

The returned PutRepositoryResponse allows to retrieve information about the executed operation as follows:

boolean acknowledged = response.isAcknowledged(); 

Indicates the node has acknowledged the request