0

我们正在从 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

4

1 回答 1

0

对于映射,请使用 GetMappings 请求:

ImmutableOpenMap<String, ?> mappings = esclient.admin().indices().getMappings(new GetMappingsRequest()).actionGet().getMappings();

您还可以指定所需的索引。

编辑:啊,我明白了,你的意思是:

client.indices().getMapping(new GetMappingsRequest().indices("index_name1", "index_name2"), RequestOptions.DEFAULT);
client.indices().getSettings(new GetSettingsRequest().indices("index_name1", "index_name2"), RequestOptions.DEFAULT);

当“客户端”是高级 REST 客户端的一个实例时。

于 2020-11-30T11:11:21.847 回答