Search code examples
javaelasticsearchupgradeelasticsearch-mappingelasticsearch-high-level-restclient

GetMappings changes in Elastic Search 7.x


I've upgraded Elastic search from "2.3.4" to "7.10.0".

While making changes in application code got confused about below case of GetMappings:

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("what_should_come_here? "index1" or "type1").getSourceAsMap();

Can anyone help me out while fetching mappingdata from response in new code, what should come under get(See new code block's last line, also asked in get param)? Will that be indexName or Type name?


Solution

  • 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.

    So, in above situation i can get mappings only for index.