ElasticSearch 5.6

时间:2018-01-05 09:13:14

标签: elasticsearch elasticsearch-5

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

在Docker中本地运行的新集群上运行

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

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中相同的路径

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

2 个答案:

答案 0 :(得分:13)

我链接的文件是6.1版本。在同一文档的5.6_doc版本中,没有提及_doc是首选名称;这可能意味着使用6.x作为映射类型名称的能力将来自{{1}}版本。

答案 1 :(得分:0)

在尝试从主分支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
}