【发布时间】:2020-11-30 20:47:33
【问题描述】:
我们正在从 Transport Client 迁移到 High Level Rest Client。我们如何协调从 Transport 客户端和 Rest 高级客户端返回的 GetIndexResponse 对象的 mappings 字段的差异?
对于传输客户端,我们使用这段代码来获取索引信息:
GetIndexResponse response = client.get()
.admin()
.indices()
.prepareGetIndex()
.setFeatures(GetIndexRequest.Feature.MAPPINGS, GetIndexRequest.Feature.SETTINGS)
.setIndices(indices)
.get();
响应 mappings 字段是 ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>>
但是对于其他高级客户,mappings 字段只是一个Map<String, MappingMetadata>。
这是高级 Rest Client 的代码:
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
【问题讨论】:
标签: elasticsearch resthighlevelclient