【问题标题】:Elasticsearch issue types removalElasticsearch 问题类型删除
【发布时间】:2020-12-23 11:01:02
【问题描述】:

我正在尝试使用 Elasticsearch Ver 7.1 在 Python 中运行以下代码,但是出现以下错误:

ElasticsearchDeprecationWarning: [types removal] Using include_type_name in put mapping requests is deprecated. The parameter will be removed in the next major version.
  client.indices.put_mapping(index=indexName,doc_type='diseases', body=diseaseMapping, include_type_name=True)

接着是:

ElasticsearchDeprecationWarning: [types removal] Specifying types in document index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{id}).
  client.index(index=indexName,doc_type=docType, body={"name": disease,"title":currentPage.title,"fulltext":currentPage.content})

我应该如何修改我的代码以使其 (see here) 与 Elasticsearch 7X 版本一致?任何形式的帮助将不胜感激。

【问题讨论】:

  • 看起来代码只是抛出警告而不是错误。这只是意味着您正在使用的库的一项功能将很快从 Elasticsearch 中删除。使用与您正在使用的 ES 版本匹配的 Elasticsearch python 库版本应该可以解决此问题。
  • 非常感谢您的快速回复。如果不是错误,我会保持原样。

标签: elasticsearch


【解决方案1】:

现在这只是一个警告,但在 Elasticsearch 8 中会变成一个错误。

从最近几个版本开始,Elasticsearch 一直在计划删除索引中的索引类型

  1. ES5 - 在索引上设置 index.mapping.single_type: true 将启用将在 6.0 中强制执行的单个索引行为。
  2. 在 ES6 中 - 1 个索引内不能有超过 1 个索引类型
  3. 在 ES7 中 - 索引中的类型概念已被弃用
  4. 在 ES8 中 - 它将被删除,并且您不能在查询或插入文档时使用类型

我的建议是设计一个应用程序和映射,使其在索引中不包含类型参数

要知道弹性搜索这样做的原因这里有一个链接:https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html#_why_are_mapping_types_being_removed

【讨论】:

    【解决方案2】:

    此错误消息的一个常见问题(且难以发现)可能是端点拼写错误,例如:

    拼写错误:

    /搜索

    正确:

    /_搜索

    仔细检查您的端点是否正确,因为 ElasticSearch 可能认为您正在尝试操作(添加、更新、删除)文档并且您正在提供类型,但事实并非如此(您正在尝试调用端点)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-27
      • 1970-01-01
      相关资源
      最近更新 更多