Search code examples
restpostcurlelasticsearchput

The difference between XPOST and XPUT


I am learning Elasticsearch, I found that XPOST and XPUT are in general the same when 'update' or 'replace' documents. They all change the field values.

curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '
{
  "name": "Jane Doe"
}'

curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
{
  "doc": { "name": "Jane Doe" }
}'

So they all changed the name field to "Jane Doe". I am wondering whats the difference between XPOST and XPUT in the above context.


Solution

  • The two commands are not at all the same. The first one (with PUT) will update a full document, not only the field you're sending.

    The second one (with POST) will do a partial update and only update the fields you're sending, and not touch the other ones already present in the document.