"_doc" mapping type name not accepted in ElasticSearch 5.6
Asked Answered
A

2

16

I am looking at examples of single-type indices on ElasticSearch 5.6 to prepare for the removal of mapping types. Specifically, I am running the first example from the ElasticSearch page about the removal of types, on a fresh cluster running locally in Docker using the docker.elastic.co/elasticsearch/elasticsearch:5.6.5 image

Running the first example from section I linked to:

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

I get the following error:

{
  "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
}

I understand that fields with a leading underscore in the name are generally considered as reserved for ES internals; but I was assuming that _doc would be considered a special case starting with version 5.6, since the linked guide mentions:

Indices created in 6.x only allow a single-type per index. Any name can be used for the type, but there can be only one. The preferred type name is _doc so that index APIs have the same path as they will have in 7.0

Am I missing something, such as a cluster setting?

Averil answered 5/1, 2018 at 9:13 Comment(0)
A
16

The document I linked to is the master version. In the 6.1 or 5.6 versions of that same document, there is no mention of _doc being the preferred name; which likely means that the ability to use _doc as a mapping type name will come with future 6.x versions.

Averil answered 5/1, 2018 at 9:46 Comment(6)
You are correct — support for _doc will be added in 6.2 (github.com/elastic/elasticsearch/pull/27816) and we will use it to ease the migration away from multiple types per indexClaptrap
What should be used instead then ?Carlynne
@ChristopheRoussy anything you want - I've been using doc, which is also the default on the elasticsearch_dsl python library.Averil
Ok so it does not matter technically, but something like doc is a hint for humans.Carlynne
I suppose doc will not work for elastisearch 7.x and later, where the mapping types are completely removed, right? Do we even have a choice to be both compatible with 7.x and 5.6?Islas
@chefarov re "do we even have a choice..." alas probably not. just have to deal with it somehow... (myself included because I just ran across this issue...). I was hoping to use _doc but now will use doc. when i start using elastic >= 6.2 i'll just have to update my code to replace doc with _doc. and fix all the indexes.Serotine
P
0

I got the same issue while trying examples in the readme file from master branch 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
}

Just checkout to the branch for version 5.6 https://github.com/elastic/elasticsearch/tree/5.6 and it looks everything is fine.

$ 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
}
Prospectus answered 22/6, 2020 at 10:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.