【问题标题】:"_doc" mapping type name not accepted in ElasticSearch 5.6ElasticSearch 5.6 不接受“_doc”映射类型名称
【发布时间】:2018-06-15 01:51:34
【问题描述】:

我正在查看 ElasticSearch 5.6 上的单一类型索引示例,以准备删除映射类型。具体来说,我正在使用 docker.elastic.co/elasticsearch/elasticsearch:5.6.5 映像在 Docker 中本地运行的新集群上运行来自 ElasticSearch page about the removal of types 的第一个示例

从我链接到的部分运行第一个示例:

PUT localhost:9200/users
{
  "settings": {
    "index.mapping.single_type": true
  },
  "mappings": {
    "_doc": {
      "properties": {
        "name": {
          "type": "text"
        },
        "user_name": {
          "type": "keyword"
        },
        "email": {
          "type": "keyword"
        }
      }
    }
  }
}

我收到以下错误:

{
  "error": {
    "root_cause": [
      {
        "type": "invalid_type_name_exception",
        "reason": "mapping type name [_doc] can't start with '_'"
      }
    ],
    "type": "invalid_type_name_exception",
    "reason": "mapping type name [_doc] can't start with '_'"
  },
  "status": 400
}

我了解名称中带有前导下划线的字段通常被认为是为 ES 内部保留的;但我假设_doc 将被视为从版本5.6 开始的特殊情况,因为链接指南提到:

在 6.x 中创建的索引只允许每个索引使用单一类型。该类型可以使用任何名称,但只能有一个。首选类型名称是 _doc,以便索引 API 具有与 7.0 中相同的路径

我是否遗漏了某些内容,例如集群设置?

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    我链接的文档是master 版本。在同一文档的6.15.6 版本中,没有提到_doc 是首选名称;这可能意味着使用_doc 作为映射类型名称的功能将在未来的6.x 版本中提供。

    【讨论】:

    • 你是对的——6.2 (github.com/elastic/elasticsearch/pull/27816) 中将添加对_doc 的支持,我们将使用它来简化从每个索引的多种类型的迁移
    • 那应该用什么代替呢?
    • @ChristopheRoussy 任何你想要的 - 我一直在使用 doc,这也是 elasticsearch_dsl python 库的默认设置。
    • 我想doc 不适用于 elastisearch 7.x 及更高版本,其中映射类型已被完全删除,对吧?我们甚至可以选择同时兼容 7.x 和 5.6 吗?
    • @chefarov 重新“我们是否还有选择……”唉,可能没有。只需要以某种方式处理它......(包括我自己,因为我刚刚遇到了这个问题......)。我希望使用_doc,但现在将使用doc。当我开始使用弹性 >= 6.2 时,我只需要更新我的代码以将 doc 替换为 _doc。并修复所有索引。
    【解决方案2】:

    我在尝试主分支 https://github.com/elastic/elasticsearch/tree/master 的自述文件中的示例时遇到了同样的问题。

    $ curl -XPUT 'elastic:@localhost:9200/twitter/_doc/1?pretty' -H 'Content-Type: application/json' -d '
    {
        "user": "kimchy",
        "post_date": "2009-11-15T13:12:00",
        "message": "Trying out Elasticsearch, so far so good?"
    }'
    {
      "error" : {
        "root_cause" : [
          {
            "type" : "invalid_type_name_exception",
            "reason" : "Document mapping type name can't start with '_', found: [_doc]"
          }
        ],
        "type" : "invalid_type_name_exception",
        "reason" : "Document mapping type name can't start with '_', found: [_doc]"
      },
      "status" : 400
    }
    

    只需签出 5.6 版的分支 https://github.com/elastic/elasticsearch/tree/5.6,看起来一切都很好。

    $ curl -XPUT 'http://localhost:9200/twitter/user/kimchy?pretty' -H 'Content-Type: application/json' -d '{ "name" : "Shay Banon" }'
    {
      "_index" : "twitter",
      "_type" : "user",
      "_id" : "kimchy",
      "_version" : 1,
      "result" : "created",
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "created" : true
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-14
      • 1970-01-01
      • 2016-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-18
      • 2014-03-10
      • 1970-01-01
      相关资源
      最近更新 更多