我们正在从 Transport Client 迁移到 High Level Rest Client。我们如何调和从 Transport 客户端与 Rest 高级客户端返回的对象mappings
字段的差异?GetIndexResponse
对于传输客户端,我们使用此代码获取索引信息:
GetIndexResponse response = client.get()
.admin()
.indices()
.prepareGetIndex()
.setFeatures(GetIndexRequest.Feature.MAPPINGS, GetIndexRequest.Feature.SETTINGS)
.setIndices(indices)
.get();
响应mappings
字段是 aImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>>
但是对于其他高级客户端,该mappings
字段只是一个Map<String, MappingMetadata>
. 这是高级休息客户端的代码:
GetIndexRequest request = new GetIndexRequest(indices);
request.addFeatures(GetIndexRequest.Feature.MAPPINGS, GetIndexRequest.Feature.SETTINGS);
try {
GetIndexResponse response = esClient.indices().get(request, RequestOptions.DEFAULT);
return
} catch (IOException ex) {
throw new SafeRuntimeException(ex);
}
}
这些是响应对象类: 传输客户端:org.elasticsearch.action.admin.indices.get.GetIndexResponse
休息高级客户端:org.elasticsearch.client.indices.GetIndexResponse