# How to calculate elapsed time between two events in different documents

**URL:** <https://discuss.elastic.co/t/how-to-calculate-elapsed-time-between-two-events-in-different-documents/292522>\
**Category:** Elasticsearch\
**Created:** [December 21, 2021, 5:42am UTC](https://discuss.elastic.co/t/how-to-calculate-elapsed-time-between-two-events-in-different-documents/292522 "2021-12-21T05:42:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![syunusic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/syunusic/32/4131_2.png) [@syunusic](https://discuss.elastic.co/u/syunusic)\
**Post date:** [December 21, 2021, 5:42am UTC](https://discuss.elastic.co/t/how-to-calculate-elapsed-time-between-two-events-in-different-documents/292522/1 "2021-12-21T05:42:08Z")

</div>

Hi all,  
If I have a log with:

- @timestamp
- EVENTNO (Event number) and
- DEVICEID (Device ID)

and this happen: always when a specific event occurs, it does have a start (`EVENTNO="300095"`) and an end (`EVENTNO="300096"`). I need to know how much time is between both events.

What I'm trying is to have in the same document both times. So far, when `EVENTNO 300095` occurs, I copy @timestamp as **t\_start** (and the same when `event 300096` occurs, I copy it as **t\_end** ). The problem that both times are in different documents (another problem is a DEVICEID can have multiple events like this, so I can't just update the docs using DEVICEID as the key/ID).

It would be great to have something like **"update until you update ONCE the field t\_end"** , but I guess that doesn't exists.

I tried with EQL, and when I used sequences, I got pairs of events (300095 and 300096) from the same DECIVEID, but the join\_keys were wrong, I don't know why.

Any ideas on how to approach this problem?

---

<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:** [January 18, 2022, 5:42am UTC](https://discuss.elastic.co/t/how-to-calculate-elapsed-time-between-two-events-in-different-documents/292522/2 "2022-01-18T05:42:14Z")

</div>

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