Get Alias API

edit

Get Alias Request

edit

The Get Alias API uses GetAliasesRequest as its request object. One or more aliases can be optionally provided either at construction time or later on through the relevant setter method.

GetAliasesRequest request = new GetAliasesRequest();
GetAliasesRequest requestWithAlias = new GetAliasesRequest("alias1");
GetAliasesRequest requestWithAliases =
        new GetAliasesRequest(new String[]{"alias1", "alias2"});

Optional arguments

edit

The following arguments can optionally be provided:

request.aliases("alias"); 

One or more aliases to retrieve

request.indices("index"); 

The index or indices that the alias is associated with

request.indicesOptions(IndicesOptions.lenientExpandOpen()); 

Setting IndicesOptions controls how unavailable indices are resolved and how wildcard expressions are expanded when looking for aliases that belong to specified indices.

request.local(true); 

The local flag (defaults to false) controls whether the aliases need to be looked up in the local cluster state or in the cluster state held by the elected master node

Synchronous Execution

edit
GetAliasesResponse response = client.indices().getAlias(request, RequestOptions.DEFAULT);

Asynchronous Execution

edit

The asynchronous execution of a get alias request requires both a GetAliasesRequest instance and an ActionListener instance to be passed to the asynchronous method:

client.indices().getAliasAsync(request, RequestOptions.DEFAULT, listener); 

The GetAliasesRequest 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 the Boolean response looks like:

ActionListener<GetAliasesResponse> listener =
        new ActionListener<GetAliasesResponse>() {
            @Override
            public void onResponse(GetAliasesResponse getAliasesResponse) {
                
            }

            @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

Get Alias Response

edit

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

Map<String, Set<AliasMetaData>> aliases = response.getAliases(); 

Retrieves a map of indices and their aliases