LaVOZs

The World’s Largest Online Community for Developers

'; Document Versioning Elasticsearch: How do I compare different document versions? - LavOzs.Com

Just discovered that Elasticsearch features versioning of documents. Awesome! Truly.

But what is the right approach to compare different versions of a document and have all differences extracted. Is there a query for that available or would I have to do that in the business logic?

elasticsearch keeps by default track of the version of the indexed documents within the _version field. That means that the first time you index a document it'll get the version 1, and every time you update it its version will be incremented.

It doesn't mean that elasticsearch keeps all the versions of the document.

The version is handy especially if you need to perform optimistic locking. Let's say you get a document and you want to update it, you can make sure you are updating that same version of the document and not other versions that could have been generated by concurrent updates (which might have happened between your get and your update).

You can have a look at this blog to know more and see it in practice.

Related
How to search for a part of a word with ElasticSearch
Elasticsearch: Disable the Versioning of index document
Elasticsearch - Maintaining Document History
Counting number of documents using Elasticsearch
elasticsearch-hadoop for Spark. Send documents from a RDD in different index (by day)
elasticsearch bool query combine must with OR
Grouping consecutive documents with Elasticsearch