Reputation: 270
I'm attempting to POST a document to an elasticsearch cluster I have cloud hosted via elastic cloud. I have an application currently running from TheThingsNetwork that is POSTing data just fine, however when I attempt to use postman or python requests module, I receive a 405 error when POSTing. GET requests work just fine and return a status of 200.
Here's my failed POST via postman:
Here's my successful GET via postman:
This should be something very straightforward, so I imagine I'm missing simple. Any and all help is greatly appreciated!
Upvotes: 12
Views: 57111
Reputation: 8740
The answers by @atorres757 and @atorres757 are correct.
One day, I tried to try the free trial provided by Elasticsearch's official website. And when I was supposed to create the index with below query.
POST /users
{ "first_name": "Rishikesh", "last_name": "Agrawani", "age": 29}
I got below result on Kibana DevTools console.
{
"error" : "Incorrect HTTP method for uri [/users?pretty=true] and method [POST], allowed: [GET, DELETE, PUT, HEAD]",
"status" : 405
}
Finally, I tried the below query by just appending /_doc
to the previous endpoint.
POST /users/_doc
{ "first_name": "Rishikesh", "last_name": "Agrawani", "age": 29}
which gives below result (successful).
{
"_index" : "users",
"_type" : "_doc",
"_id" : "tHTmZn0BRhCCQAKysEr1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}
Finally, we can validate the insertion with below query.
GET /users/_doc/tHTmZn0BRhCCQAKysEr1
which gives the below result.
{
"_index" : "users",
"_type" : "_doc",
"_id" : "tHTmZn0BRhCCQAKysEr1",
"_version" : 1,
"_seq_no" : 1,
"_primary_term" : 1,
"found" : true,
"_source" : {
"first_name" : "Rishikesh",
"last_name" : "Agrawani",
"age" : 29
}
}
Thanks. I haven't tried any special but just added working examples by using the available answers to make the solutions more clearer.
Upvotes: 1
Reputation:
to anyone come to this answer looking for a solution, the Elastic search
has been changed now index type is not supported since ES6
and above what you need to do is
POST -> https://youripOrDomain:9200/your_index_name/_doc/your_id
if you leave your_id
blank it will create one for you so it is optional
Upvotes: 10
Reputation: 619
This is because you're trying to POST to an index. Add a document type to the end of your url ex. /my_index/my_doc and you should be able to POST your document as my_doc document type.
Upvotes: 20