# ElasticSearch loosing data

**URL:** <https://discuss.elastic.co/t/elasticsearch-loosing-data/192873>\
**Category:** Logstash\
**Created:** [July 30, 2019, 10:35am UTC](https://discuss.elastic.co/t/elasticsearch-loosing-data/192873 "2019-07-30T10:35:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aymen\_Ben\_Moussa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aymen_ben_moussa/32/44513_2.png) [@Aymen\_Ben\_Moussa](https://discuss.elastic.co/u/Aymen_Ben_Moussa)\
**Post date:** [July 30, 2019, 10:35am UTC](https://discuss.elastic.co/t/elasticsearch-loosing-data/192873/1 "2019-07-30T10:35:01Z")

</div>

My architecture consists of Kafka logstash elasticsearch, i wrote a ruby code to calculate a KPI in logstash, everything was working fine but some days pass by and that KPI i made has been reset to 0 and only that KPI, i've also created some scripted fields in kibana i somehow messed them up and immediately got data loss when i was observing my saved search not everything but some of them, so i deleted those scripted fields and created proper ones that they where successful but after some time the same issue got back

this is my ruby code at the logstash level

> ```
> mutate { add_field => { "[@metadata][task]" => "constant" } }
> aggregate {
> task_id => "%{[@metadata][task]}"
> code => '
> map["total"] ||=0
> t = event.get("[payload][type]")
> s = event.get("[payload][status]")
> if t == "topup" && s == "success"
> map["total"] += event.get("[payload][amount]")
> elsif t == "cashout" && s == "success"
> map["total"] -= event.get("[payload][amount]")
> end
> event.set("total", map["total"])
> '
> }
> 
> ```

and the scripted fields where normal doc["fieldname"] i've just used it to rename some fields

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 30, 2019, 12:38pm UTC](https://discuss.elastic.co/t/elasticsearch-loosing-data/192873/2 "2019-07-30T12:38:53Z")

</div>

What problem are you having with that aggregate filter?

---

<div class="post-metadata">

**Author:** ![Aymen\_Ben\_Moussa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aymen_ben_moussa/32/44513_2.png) [@Aymen\_Ben\_Moussa](https://discuss.elastic.co/u/Aymen_Ben_Moussa)\
**Post date:** [July 30, 2019, 12:43pm UTC](https://discuss.elastic.co/t/elasticsearch-loosing-data/192873/3 "2019-07-30T12:43:51Z")

</div>

@Badger I still don't know yet but after a while the total field gets reset to 0 i have to delete the index and index back again to have the correct value  
ps: i'm using --pipeline.workers 1

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 30, 2019, 1:50pm UTC](https://discuss.elastic.co/t/elasticsearch-loosing-data/192873/4 "2019-07-30T13:50:34Z")

</div>

> [@Aymen\_Ben\_Moussa](#):
>
> after a while the total field gets reset to 0

I would only expect that to happen when logstash restarts.

---

<div class="post-metadata">

**Author:** ![Aymen\_Ben\_Moussa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aymen_ben_moussa/32/44513_2.png) [@Aymen\_Ben\_Moussa](https://discuss.elastic.co/u/Aymen_Ben_Moussa)\
**Post date:** [July 30, 2019, 1:56pm UTC](https://discuss.elastic.co/t/elasticsearch-loosing-data/192873/5 "2019-07-30T13:56:02Z")

</div>

@Badger I never restarted the server, i have a ec2 instance do you think when amazon automaticly backups the server it get restarted ? that is a slight chance because if it has been restarted all the other services will go down and will not automatically restart, and what about the data loss i'm facing ? is there something i can do so you can incarnate my problem ?

---

<div class="post-metadata">

**Author:** ![Aymen\_Ben\_Moussa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aymen_ben_moussa/32/44513_2.png) [@Aymen\_Ben\_Moussa](https://discuss.elastic.co/u/Aymen_Ben_Moussa)\
**Post date:** [August 1, 2019, 12:31pm UTC](https://discuss.elastic.co/t/elasticsearch-loosing-data/192873/6 "2019-08-01T12:31:35Z")

</div>

Is there a other way i can calculate that KPI probably in Elasticsearch ?

---

<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:** [August 29, 2019, 12:37pm UTC](https://discuss.elastic.co/t/elasticsearch-loosing-data/192873/7 "2019-08-29T12:37:44Z")

</div>

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