# Persisting latest state in separated index

**URL:** <https://discuss.elastic.co/t/persisting-latest-state-in-separated-index/289628>\
**Category:** Elasticsearch\
**Created:** [November 18, 2021, 6:17pm UTC](https://discuss.elastic.co/t/persisting-latest-state-in-separated-index/289628 "2021-11-18T18:17:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nestor1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nestor1/32/123438_2.png) [@nestor1](https://discuss.elastic.co/u/nestor1)\
**Post date:** [November 18, 2021, 6:17pm UTC](https://discuss.elastic.co/t/persisting-latest-state-in-separated-index/289628/1 "2021-11-18T18:17:43Z")

</div>

I have stream of data like this:

```auto
userid: 1, taskid: 1, start_time: 01:00:00, completed: 10
userid: 1, taskid: 1, start_time: 02:00:00, completed: 30
userid: 1, taskid: 1, start_time: 03:00:00, completed: 70
userid: 1, taskid: 1, start_time: 04:00:00, completed: 90

```

I want to save in another index just current states, so basically I need to delete previous state and create new stated based on `userid` and `taskid`. I mean only "completed" field should be updated, because start time is when the first event occurred anyway.

something like:  
`userid: 1, taskid: 1, start_time: 01:00:00, completed: 10`  
is current state, after that,  
`userid: 1, taskid: 1, start_time: 01:00:00, completed: 30`  
etc.., last event is  
`userid: 1, taskid: 1, start_time: 01:00:00, completed: 30, end_time: 07:00:00`

Hope I made myself clear. Is this something that should be done with some scripting, or in Logstash/Filebeat while inserting data, or should I keep just one index and adjust queries to grab only current state of the field?

Thanks

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 21, 2021, 11:39pm UTC](https://discuss.elastic.co/t/persisting-latest-state-in-separated-index/289628/2 "2021-11-21T23:39:30Z")

</div>

Look at using a transform for this - [Transforming data | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/transforms.html)

---

<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:** [December 19, 2021, 11:40pm UTC](https://discuss.elastic.co/t/persisting-latest-state-in-separated-index/289628/3 "2021-12-19T23:40:05Z")

</div>

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