Updating a document
Documents stored in ElasticSearch can be updated at any time throughout their lives. There are two available solutions to perform this operation in ElasticSearch, namely by adding the new document, or by using the update call.
The update call works in two ways:
By providing a script (based on supported ElasticSearch scripting languages) which contains the code that must be executed to update the record
By providing a document that must be merged with the original one
The main advantage of an update versus an index is the reduction in networking.
Getting ready
You will need a working ElasticSearch cluster and the indexed document of the Indexing a document recipe in this chapter. To use the dynamic scripting languages, the dynamic scripting languages must be enabled (see Chapter 7, Scripting, to learn more).
How to do it...
As we are changing the state of the data, the HTTP method is POST and the REST URL is:
http://<server>/<index_name>/<type_name>/<id>...