【问题标题】:Handling Mappings when migrating Get Index call from Transport client to Rest High Level Client将 Get Index 调用从传输客户端迁移到 Rest 高级客户端时处理映射
【发布时间】: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


    【解决方案1】:

    对于映射,请使用 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 客户端的实例时。

    【讨论】:

    • 这看起来像是通过 TransportClient 进行的呼叫,我们正在从该呼叫中迁移出去。此外,我们需要使用新的 High Level Rest Client 获取这两个设置、一组特定索引的映射。
    • 查看这些看似相似的调用的返回类型(一个是 Map 另一个是 Map>): Transport Client: ImmutableOpenMap&lt;String, ImmutableOpenMap&lt;String, MappingMetadata&gt;&gt; mappings = esclient.admin().indices().getMappings(new GetMappingsRequest()).actionGet().getMappings(); vs Rest Client : Map&lt;String, MappingMetadata&gt; mappings = client.indices().getMapping(new GetMappingsRequest(), RequestOptions.DEFAULT).mappings();跨度>
    猜你喜欢
    • 2019-07-13
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 2023-03-24
    • 2017-07-05
    • 2015-11-29
    相关资源
    最近更新 更多