Elastic Search 中的 GetMappings 更改 7.x

GetMappings changes in Elastic Search 7.x

我已将 Elastic 搜索从“2.3.4”升级到“7.10.0”。

在更改应用程序代码时对以下 GetMappings 情况感到困惑:

旧代码(2.3.4):

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

新代码(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();

谁能帮我在新代码中从响应中获取映射数据时,get 下应该包含什么(请参阅新代码块的最后一行,也在 get 参数中询问)?那是索引名称还是类型名称?

经过一些研发发现,我们可以在 ES 7.x 版本中获取索引的字段映射,但不能获取类型,因为类型在 7.0 中的 API 中已弃用。

因此,在上述情况下,我只能获取索引的映射。