Documents stored in ElasticSearch can be updated during their lives. There are two available solutions to do this operation in ElasticSearch: repost the new document or use the update call.
The update call can work in the following two ways:
By providing a script which is the update strategy
By providing a document that must be merged with the original one
You need a working ElasticSearch cluster and the indexed document which we discussed in the Indexing a document recipe.
As we are changing the state of the data the HTTP method is POST and the following is the REST URL:
http://<server>/<index_name>/<type_name>/<id>/_update
For updating a document, we need to perform the following steps:
If we consider the type
order
of the previous recipe, the call to update a document will be as follows:curl -XPOST 'http://localhost:9200/myindex/order/2qLrAfPVQvCRMe7Ku8r0Tw/_update' –d '{ "script" : "ctx._source.in_stock_items += count...