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

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

ResizeResponse resizeResponse = client.indices().split(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

edit

Executing a ResizeRequest 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 split-index method:

client.indices().splitAsync(request, RequestOptions.DEFAULT,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. Failure scenarios and expected exceptions are the same as in the synchronous execution case.

A typical listener for split-index 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.

Called when the whole ResizeRequest fails.

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