Difference between XPOST and XPUT
elasticsearch, rest
Solution
Generally when using a REST API: - POST is used to create a resource, where the server will pick an ID. - PUT is used to update OR PLACE a resource at a known ID.
Doc creation examples in the ES documentation show the caller picking an ID.
Like so:
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}'
Since the caller is picking the ID a PUT seems appropriate here.
BUT
using POST Elasticsearch can also generate an ID for you.
$ curl -XPOST 'http://localhost:9200/twitter/tweet/' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}'
Problem
I'm just starting to use ElasticSearch. And I tried to know how to insert documents. I only found examples using the PUT method : `$ curl -XPUT 'http://localhost:9200/...'` But it also seems to work using POST. Is there any difference between these two methods? Thank you.