【问题标题】:ElasticSearch: Specifying types in bulk requests is deprecatedElasticSearch:不推荐在批量请求中指定类型
【发布时间】:2019-10-18 13:07:47
【问题描述】:

我收到警告:

"[types removal] Specifying types in bulk requests is deprecated."]

我做错了什么?这是我的代码:

    BulkRequest request = new BulkRequest();

    for(Item item : items) {
        IndexRequest indexRequest = new IndexRequest(INDEX_NAME, DOC_TYPE, item.getIdentifier());
        indexRequest
                .opType(DocWriteRequest.OpType.INDEX) // Index the source. If there an existing document with the id, it will be replaced.
                .source(JsonUtility.toJson(item), XContentType.JSON);

        request.add(indexRequest);
    }

    elastic.bulk(request, RequestOptions.DEFAULT);

【问题讨论】:

  • 您可能正在使用 ES 7.0 或更高版本。检查你的版本
  • @JBone ,我收到了同样的警告信息,我正在使用带有 Spring Boot 的 7.4.0 版本,我该如何解决这个问题?,我应该怎么做?。
  • 这个stackoverflow.com/questions/62322613/… 也可能导致该消息并且很难发现。基本上 - 如果您拼错端点,您会收到此错误消息。不确定它是否会发生在 ES 更高级别的客户端上,但值得一提的是,它花了大约一个小时才意识到。

标签: java elasticsearch


【解决方案1】:

映射 typeremoved in Elasticsearch 8,在 Elasticsearch 7 中已弃用。

您的问题中没有提到Elasticsearch 版本,但您可以阅读有关schedule for removal of mapping types 的更多信息,并做出相应的反应。

【讨论】:

    【解决方案2】:

    我认为您正在使用 7.X 版本,问题是您创建 IndexRequest 正在构建 POST 方法的 URL 以在 ElasticSearch 中搜索,类似于:

    • http://localhost:9200/INDEX_NAME_identifier/DOC_TYPE/_search

    其中标识符是用于在搜索中进行区分的属性。在 ElasticSearch 7 中,不推荐在搜索请求中指定类型,并且 URL 应该接近于:

    • http://localhost:9200/INDEX_NAME_identifier/_search

    虽然由于您没有指定版本而很难知道,但我认为您代码中的 elasticsearch 库早于 7.X,如果您将其更新为 7,则 DOC_TYPE 参数可能会在构造函数中消失。

    【讨论】:

      猜你喜欢
      • 2020-05-09
      • 2021-03-03
      • 2021-04-02
      • 2022-01-06
      • 2021-02-05
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      相关资源
      最近更新 更多