Get Field Mappings APIedit

Get Field Mappings Requestedit

A GetFieldMappingsRequest can have an optional list of indices, optional list of types and the list of fields:

GetFieldMappingsRequest request = new GetFieldMappingsRequest(); 
request.fields("message", "timestamp"); 

An empty request

Setting the indices to fetch mapping for

The types to be returned

The fields to be returned

Optional argumentsedit

The following arguments can also optionally be provided:


Setting IndicesOptions controls how unavailable indices are resolved and how wildcard expressions are expanded


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 Executionedit

GetFieldMappingsResponse response =
    client.indices().getFieldMapping(request, RequestOptions.DEFAULT);

Asynchronous Executionedit

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

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

The GetFieldMappingsRequest 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<GetFieldMappingsResponse> listener =
    new ActionListener<GetFieldMappingsResponse>() {
        public void onResponse(GetFieldMappingsResponse 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 Field Mappings Responseedit

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

final Map<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>>> mappings =
final Map<String, GetFieldMappingsResponse.FieldMappingMetaData> typeMappings =
final GetFieldMappingsResponse.FieldMappingMetaData metaData =

final String fullName = metaData.fullName();
final Map<String, Object> source = metaData.sourceAsMap(); 

Returning all requested indices fields' mappings

Retrieving the mappings for a particular index and type

Getting the mappings metadata for the message field

Getting the full name of the field

Getting the mapping source of the field