【问题标题】:How to create index type and id in create index request?如何在创建索引请求中创建索引类型和 id?
【发布时间】:2020-04-13 14:39:20
【问题描述】:

我正在使用来自 elastic 6.3.2 的 IndexRequest。现在我更改为 7.6.2 版本。如何使用 CreateIndexRequest 执行以下相同步骤?

Elastic rest 高级客户端 6.3.2 代码:

 public Object createIndex(Object document, String id) throws IOException {

        Map documentMapper = objectMapper.convertValue(document, Map.class);

        IndexRequest indexRequest = new IndexRequest(this.getIndexName(),
                type, id).source(documentMapper, XContentType.JSON);

        IndexResponse indexResponse = client.index(indexRequest);
        return null;
    }

切换到 7.6.2 后,我无法在 CreateIndexRequest 中创建类型、id 和源。

【问题讨论】:

    标签: java spring elasticsearch elastic-stack resthighlevelclient


    【解决方案1】:

    类型在 Elasticsearch 7.X 中被弃用,下面是代码,它适用于我使用 resthighlevel 客户端。

    请注意我没有在resthighlevel客户端的CreateIndexRequest方法中使用typeid

    String indexString = jsonUtil.getStringFromFile(indexName + ".mapping");
    CreateIndexRequest request = new CreateIndexRequest(indexName);
    request.source(indexString, XContentType.JSON);
    client.indices().create(request, RequestOptions.DEFAULT);
    

    请查看removal of types了解更多信息。

    【讨论】:

      猜你喜欢
      • 2018-03-27
      • 2010-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-28
      • 1970-01-01
      • 2016-01-10
      相关资源
      最近更新 更多