A GetMappingsRequest
can have an optional list of indices and optional list of types:
GetMappingsRequest request = new GetMappingsRequest();
request.indices("twitter");
request.types("_doc");
|
An empty request that will return all indices and types
|
|
Setting the indices to fetch mapping for
|
|
The types to be returned
|
The following arguments can also optionally be provided:
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.indicesOptions(IndicesOptions.lenientExpandOpen());
|
Options for expanding indices names
|
Synchronous Execution
edit
GetMappingsResponse getMappingResponse = client.indices().getMapping(request, RequestOptions.DEFAULT);
Asynchronous Execution
edit
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>() {
@Override
public void onResponse(GetMappingsResponse putMappingResponse) {
}
@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 Mappings Response
edit
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
|