Get Mappings APIedit

Get Mappings Requestedit

A GetMappingsRequest can have an optional list of indices and optional list of types:

GetMappingsRequest request = new GetMappingsRequest(); 

An empty request that will return all indices and types

Setting the indices to fetch mapping for

The types to be returned

Optional argumentsedit

The following arguments can also optionally be provided:


Timeout to connect to the master node as a TimeValue

Timeout to connect to the master node as a String


Options for expanding indices names

Synchronous Executionedit

GetMappingsResponse getMappingResponse = client.indices().getMapping(request, RequestOptions.DEFAULT);

Asynchronous Executionedit

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

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

The GetMappingsRequest 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 GetMappingsResponse looks like:

ActionListener<GetMappingsResponse> listener =
    new ActionListener<GetMappingsResponse>() {
        public void onResponse(GetMappingsResponse putMappingResponse) {

        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 Mappings Responseedit

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

ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> allMappings = getMappingResponse.mappings(); 
MappingMetaData typeMapping = allMappings.get("twitter").get("_doc"); 
Map<String, Object> mapping = typeMapping.sourceAsMap(); 

Returning all indices' mappings

Retrieving the mappings for a particular index and type

Getting the mappings as a Java Map