Can't use _doc as type despite it being declared the preferred method


(Jay Janssen) #1

Ok, I'm at a loss. I'm starting to work with 6.0 and I read here that the preferred type name in 6.x is '_doc'. However, when I try to PUT a new document, I get an error from the (6.0.1) server:

Document mapping type name can't start with '_'

I am using the precise example from the 6.x manual for UPDATE and further if I use 'doc' instead '_doc', it works fine.

Is the joke on me?

$ curl localhost:32798
{
  "name" : "IsUdPpi",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "0pvQUrwaSc-wO9f7XAA87w",
  "version" : {
    "number" : "6.0.1",
    "build_hash" : "601be4a",
    "build_date" : "2017-12-04T09:29:09.525Z",
    "build_snapshot" : false,
    "lucene_version" : "7.0.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

$ curl -XPUT 'localhost:32798/test/_doc/1?pretty' -H 'Content-Type: application/json' -d'
{
    "counter" : 1,
    "tags" : ["red"]
}
'
{
  "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
}

$ curl -XPUT 'localhost:32798/test/doc/2?pretty' -H 'Content-Type: application/json' -d'
{
    "counter" : 1,
    "tags" : ["red"]
}
'
{
  "_index" : "test",
  "_type" : "doc",
  "_id" : "2",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

(Jay Janssen) #2

Apparently I shouldn't read the 6.x documentation

References _doc:
https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html#_schedule_for_removal_of_mapping_types

Most references to _doc are gone:
https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html#_schedule_for_removal_of_mapping_types

Clear as mud


(SK) #3

Facing the same issue.


(Herman) #4

Same issue. Did you get an answer somewhere?


(Jay Janssen) #5

The answer seems to be that they were going to standardize on _doc, but changed their minds at some point. AFAICT, you can standardize on whatever you like, just not something that has an underscore. I chose 'doc'.


(Herman) #6

What version of Elastic are you using?

I was using 6.1.3 and _doc was a problem. Then switched to 6.2.1 and you can use _doc without any issues.

Any other name starting with _, however, gives an error:
"type": "invalid_type_name_exception",
"reason": "mapping type name [vdoc] can't start with '' unless it is called [_doc]"

It seems 6.2.1 is in line with the documentation


(Jay Janssen) #7

I believe I was testing 6.1 or maybe a 6.0 version at the time. I can't upgrade to 6.x yet because of Creating new types in 6.0.


(Lory Hou) #8

change _doc to doc


(Jason Tedor) #9

Sorry for the confusion, we addressed this in 6.2.0: https://github.com/elastic/elasticsearch/pull/27816


(system) #10

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.