# How to store document history (versioning, revisions)?

**URL:** <https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651>\
**Category:** Elasticsearch\
**Created:** [October 21, 2015, 9:29am UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651 "2015-10-21T09:29:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mos/32/4898_2.png) [@mos](https://discuss.elastic.co/u/mos)\
**Post date:** [October 21, 2015, 9:29am UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/1 "2015-10-21T09:29:12Z")

</div>

We have a very common requirement: On every document update, we need to store the old version. Thus we would have a complete history of document changes.

I plan to build a second index that holds all the archived documents. Hence before updating a document, it would be reindexed in this second index. Does this make sense? Or is there a build-in function or a plugin for doing such document-revisions.

Another aspect: We would like to save just the DIFF between the new document and the old one. Is there a build-in mechanism or plugin for doing this?

Thanks for helping out 😌

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 21, 2015, 9:51am UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/2 "2015-10-21T09:51:14Z")

</div>

> Another aspect: We would like to save just the DIFF between the new document and the old one. Is there a build-in mechanism or plugin for doing this?

And the point would be to save disk space, or what's the background?

---

<div class="post-metadata">

**Author:** ![mos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mos/32/4898_2.png) [@mos](https://discuss.elastic.co/u/mos)\
**Post date:** [October 21, 2015, 11:02am UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/3 "2015-10-21T11:02:01Z")

</div>

> [@magnusbaeck](#):
>
> > We would like to save just the DIFF between the new document and the old one.  
> > And the point would be to save disk space, or what's the background?

Exactly!

---

<div class="post-metadata">

**Author:** ![mos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mos/32/4898_2.png) [@mos](https://discuss.elastic.co/u/mos)\
**Post date:** [October 22, 2015, 9:20am UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/4 "2015-10-22T09:20:07Z")

</div>

Anyone some hints or opinions on document revisions?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [October 22, 2015, 9:37am UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/5 "2015-10-22T09:37:30Z")

</div>

Our only built-in notion of versioning is limited to incrementing the version number attached to a single instance of a doc whenever it is updated. This is there to support optimistic-locking style use cases, not for maintaining multiple concurrent versions in the index.  
If you want multiple versions in the index they will need to be managed in your application code and you will typically also have to worry about de-duping versions in search results.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 22, 2015, 9:43am UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/6 "2015-10-22T09:43:15Z")

</div>

I am interested in writing a plugin for ES that implements JSON Patch

[http://tools.ietf.org/html/rfc6902](http://tools.ietf.org/html/rfc6902)

together with HTTP PATCH

[https://tools.ietf.org/html/rfc5789](https://tools.ietf.org/html/rfc5789)

and storing the patches beside the document could be one nice side effect.

Maybe it is that kind of feature you are looking for? I'm not sure, because it does not save space at all, it will increase resource usage.

---

<div class="post-metadata">

**Author:** ![mos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mos/32/4898_2.png) [@mos](https://discuss.elastic.co/u/mos)\
**Post date:** [October 22, 2015, 10:45am UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/7 "2015-10-22T10:45:50Z")

</div>

Thanks guys. Ok, I will go with a second index where I store the archived versions. The patch stuff seems very interesting..

---

<div class="post-metadata">

**Author:** ![tirupathi](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@tirupathi](https://discuss.elastic.co/u/tirupathi)\
**Post date:** [April 18, 2016, 4:53pm UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/8 "2016-04-18T16:53:13Z")

</div>

I am also looking for similar solution, any plugins or tools to

---

<div class="post-metadata">

**Author:** ![thatiguy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thatiguy/32/9535_2.png) [@thatiguy](https://discuss.elastic.co/u/thatiguy)\
**Post date:** [May 3, 2016, 4:49pm UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/9 "2016-05-03T16:49:09Z")

</div>

One possibility is to store all documents in JSON Patch notation, where the very first document is made up of all 'Add' operations. After that, store all subsequent operations in time order. You can keep an effective document that represents the most current document for quicker retrieval.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:54pm UTC](https://discuss.elastic.co/t/how-to-store-document-history-versioning-revisions/32651/10 "2017-07-05T22:54:19Z")

</div>


