Split Index API

edit

Resize Request

edit

The Split API requires a ResizeRequest instance. A ResizeRequest requires two string arguments:

ResizeRequest request = new ResizeRequest("target_index","source_index"); 
request.setResizeType(ResizeType.SPLIT); 

The target index (first argument) to split the source index (second argument) into

The resize type needs to be set to SPLIT

Optional arguments

edit

The following arguments can optionally be provided:

request.timeout(TimeValue.timeValueMinutes(2)); 
request.timeout("2m"); 

Timeout to wait for the all the nodes to acknowledge the index is opened as a TimeValue

Timeout to wait for the all the nodes to acknowledge the index is opened as a String

request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); 
request.masterNodeTimeout("1m"); 

Timeout to connect to the master node as a TimeValue

Timeout to connect to the master node as a String

request.setWaitForActiveShards(2); 
request.setWaitForActiveShards(ActiveShardCount.DEFAULT); 

The number of active shard copies to wait for before the split index API returns a response, as an int

The number of active shard copies to wait for before the split index API returns a response, as an ActiveShardCount

request.getTargetIndexRequest().settings(Settings.builder()
        .put("index.number_of_shards", 4)); 

The settings to apply to the target index, which include the number of shards to create for it

request.getTargetIndexRequest().alias(new Alias("target_alias")); 

The aliases to associate the target index with

Synchronous Execution

edit
ResizeResponse resizeResponse = client.indices().split(request);

Asynchronous Execution

edit

The asynchronous execution of a split index request requires both the ResizeRequest instance and an ActionListener instance to be passed to the asynchronous method:

client.indices().splitAsync(request,listener); 

The ResizeRequest 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 ResizeResponse looks like:

ActionListener<ResizeResponse> listener = new ActionListener<ResizeResponse>() {
    @Override
    public void onResponse(ResizeResponse resizeResponse) {
        
    }

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

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

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

Split Index Response

edit

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

boolean acknowledged = resizeResponse.isAcknowledged(); 
boolean shardsAcked = resizeResponse.isShardsAcknowledged(); 

Indicates whether all of the nodes have acknowledged the request

Indicates whether the requisite number of shard copies were started for each shard in the index before timing out