Indexing a document - "error": "Incorrect HTTP method for uri [/animals/_doc/] and method [PUT], allowed: [POST]",

I created the Index manually (Mappings and Settings sections) instead of letting ElasticSearch create one. I am able to see the structure of the "animals" index file. It looks like below.
When I use PUT command to insert a document it throws the error.

          PUT /animals/_doc/
             { "animal-type":"carnivore",
                "eating-type": "chewing",
                "legs": 4,
                 "name": "Dog",
                  "tail": true
               }

                   {
                        "animals": {
                        "aliases": {},
                              "mappings": {
                                       "doc": {
                                       "properties": {
                                                     "animal-type": {
                                                            "type": "text"
                                                    },
                                                  "eating-type": {
                                                          "type": "text"
                                                   },
                                                  "legs": {
                                                        "type": "integer"
                                                   },
                                                   "name": {
                                                           "type": "text",
                                                            "analyzer": "standard"
                                                   },
                                                   "tail": {
                                                              "type": "boolean"
                                                   }
                             }
                      }
                  },
                              "settings": {
                                       "index": {
                                         "creation_date": "1520447645771",
                                         "number_of_shards": "2",
                                         "number_of_replicas": "2",
                                         "uuid": "r6CMK66vSlqt669SsRWnvA",
                                        "version": {
                                                 "created": "6020299"
                                          },
                                       "provided_name": "animals"
                                  }
                            }
                     }
                     }

You need to use POST if you're not specifying a document id. Generally POST will create, PUT is for updating.

1 Like

Jon,

I tried POST as well. I am getting
"statusCode": 400,
"error": "Bad Request",
"message": "child "method" fails because ["method" must be one of [HEAD, GET, POST, PUT, DELETE]]",

    POST/animals/_doc/
         { "animal-type":"carnivore",
            "eating-type": "chewing",
            "legs": 4,
              "name": "Dog",
              "tail": true
        }

Hmm. Can you make sure there's a space between POST and /animals?

POST /animals/_doc

I am getting:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [animals] as the final mapping would have more than 1 type: [_doc, doc]"
}
],
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [animals] as the final mapping would have more than 1 type: [_doc, doc]"
},
"status": 400
}

Progress! POST /animals/doc should get us moving. We created a 'doc' _type in the other thread, and because we're only allowed one type it needs to match exactly.

1 Like

You are correct!! It works now.

can you point me to some documentation?
What is the difference between "_doc" and "doc" ? it is confusing for me.

Since I said "doc" when I was creating the structure, when I am using POST, I have to use "doc" not "_doc".

When I am creating the structure whatever name I used, I should use same name when inserting a document into that index.

So what is the significance of "doc" that I used in the command PUT /houses/_mapping/doc

From Elasticsearch 6.0 version we don't have Types (like Tables in RDBM) in an index anymore. If I understood correctly.

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