Updating Documents

Published on January 17, 2016 by

Now instead of replacing a document, often times you will want to update it with some new information. Instead of replacing our entire product in order to change the price, we can just… well, change the price! This means that we don’t have to supply all of the fields again, but that we only have to pass in the fields that we want to update. We can do this by issuing a POST request as can be seen below.

POST /ecommerce/product/1001/_update
{
  "doc": { "price": "50.00" }
}

Simply nest key-value pairs with a doc property for the fields that you wish to change, along with their new values.

The above request will change the price to 30 and leave the rest of the document’s fields unchanged. If you wish, go to Kibana and verify that the price has indeed been updated, and that the other fields are the same. So this is how you can update certain fields of a document without replacing the entire document, which is quite convenient.

Featured

Learn Elasticsearch today!

Take an online course and become an Elasticsearch champion!

Here is what you will learn:

  • The architecture of Elasticsearch
  • Mappings and analyzers
  • Many kinds of search queries (simple and advanced alike)
  • Aggregations, stemming, auto-completion, pagination, filters, fuzzy searches, etc.
  • ... and much more!
Elasticsearch logo
Author avatar
Bo Andersen

About the Author

I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!

Leave a Reply

Your e-mail address will not be published.