# History of updates modeling

**URL:** <https://discuss.elastic.co/t/history-of-updates-modeling/358865>\
**Category:** Elasticsearch\
**Created:** [May 6, 2024, 5:30pm UTC](https://discuss.elastic.co/t/history-of-updates-modeling/358865 "2024-05-06T17:30:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hafssa\_askaoui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hafssa_askaoui/32/134183_2.png) [@hafssa\_askaoui](https://discuss.elastic.co/u/hafssa_askaoui)\
**Post date:** [May 6, 2024, 5:30pm UTC](https://discuss.elastic.co/t/history-of-updates-modeling/358865/1 "2024-05-06T17:30:04Z")

</div>

I'm newbie to Elasticsearch and I'm wondering about the best way to model this requirement in Elasticsearch: we need to keep the modification history of an object like this:

example{  
id;  
name;  
type;  
}

So far, we've followed this approach: every time the object is modified, a new document is inserted into Elasticsearch. I also need to create ratio metrics on the type within a period, considering only the last document of each object within that period, based on a date field added to the object. This makes the query complicated and involves several sub-aggregations.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 6, 2024, 7:15pm UTC](https://discuss.elastic.co/t/history-of-updates-modeling/358865/2 "2024-05-06T19:15:58Z")

</div>

Have you considered having 2 separate indices - one in which you always store the latest version by performing an update and one where you store each update as a separate document? If you want the current version you efficiently query the first index and if you are looking at changes over time you query the second.

---

<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:** [June 3, 2024, 7:16pm UTC](https://discuss.elastic.co/t/history-of-updates-modeling/358865/3 "2024-06-03T19:16:54Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
