0
votes

I've upgraded Elastic search from "2.3.4" to "7.10.0". I wanna upgrade existing code of getting mapping for a specific index and type. Please refer below code(old and new).

old code(2.3.4):

Map<String, Object> mappingMeta = client.admin().indices().prepareGetMappings("index1").get().mappings().get("index1").get("type1").getSourceAsMap();

new code(7.10.0):

GetMappingsRequest mappingsRequest = new GetMappingsRequest();
mappingsRequest.indices("index1");
GetMappingsResponse mappingsResponse = client.indices().getMapping(mappingsRequest, RequestOptions.DEFAULT);
Map<String, Object> mappingMeta = mappingsResponse.mappings().get("index1").getSourceAsMap();

In new code changes, i can get mappings only for an index. How to get mappings for a type("type1" in old code) in ES 7.10.0?

1
Types are deprecated in APIs in 7.0, with breaking changes to the index creation, put mapping, get mapping, put template, get template and get field mappings APIs. Please check this elastic.co/guide/en/elasticsearch/reference/current/…Sagar Patel

1 Answers

0
votes

After some R&D found that We can get field mappings for an index in ES 7.x versions but can't for a type as Types are deprecated in APIs in 7.0.

ES(Before 6.7) GetMapping For Index and Type:

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

ES 7.x GetMapping Only for Index:

Map<String, MappingMetadata> allMappings = getMappingResponse.mappings();
MappingMetadata indexMapping = allMappings.get("index_name");
Map<String, Object> mapping = indexMapping.sourceAsMap();