# How to index state changes?

**URL:** <https://discuss.elastic.co/t/how-to-index-state-changes/167941>\
**Category:** Elasticsearch\
**Created:** [February 11, 2019, 10:50pm UTC](https://discuss.elastic.co/t/how-to-index-state-changes/167941 "2019-02-11T22:50:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiclasK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niclask/32/47189_2.png) [@NiclasK](https://discuss.elastic.co/u/NiclasK)\
**Post date:** [February 11, 2019, 10:50pm UTC](https://discuss.elastic.co/t/how-to-index-state-changes/167941/1 "2019-02-11T22:50:15Z")

</div>

Hi,

I have a process that I want to monitor/analyze using elastic search. The process takes place on thousand's of embedded devices. I am wondering what is the preferred format to send the data to elastic search to have flexibility to look at different properties.  
My initial idea is to send json a series of documents like  
{  
"deviceId": "abc123",  
"seqId": 1,  
"state": "stat\_1",  
"prevState": "state\_0",  
"date": "2019-02-11T18:25:43",  
"measuredValue": 1.27  
}  
Every time there is a state change in the process a message like the one above will be sent with the new and old state and some other data. Once the process finishes it starts over, but with a new seqId.  
I would like to be able look (both for one device or many devices) at e.g.:

- How long time that is spent in different states.
- How long time between any two states.
- make histogram over measured values

I'm not sure how to add this data to elastic search, especially how to be able to calculate the time difference. Or is there a better format to send the data in?

Thanks!

---

<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:** [February 12, 2019, 8:01am UTC](https://discuss.elastic.co/t/how-to-index-state-changes/167941/2 "2019-02-12T08:01:06Z")

</div>

Analysing behaviour of many actors often requires an [entity centric index](https://twitter.com/elasticmark/status/1009380268409610240?s=21) alongside your event-centric log index

---

<div class="post-metadata">

**Author:** ![NiclasK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niclask/32/47189_2.png) [@NiclasK](https://discuss.elastic.co/u/NiclasK)\
**Post date:** [February 12, 2019, 5:06pm UTC](https://discuss.elastic.co/t/how-to-index-state-changes/167941/3 "2019-02-12T17:06:27Z")

</div>

Thanks, I will have a look at that!

---

<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:** [March 12, 2019, 5:06pm UTC](https://discuss.elastic.co/t/how-to-index-state-changes/167941/4 "2019-03-12T17:06:39Z")

</div>

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