# Time Difference between two logs

**URL:** https://discuss.elastic.co/t/time-difference-between-two-logs/314028
**Category:** Kibana
**Created:** [September 9, 2022, 3:14am UTC](https://discuss.elastic.co/t/time-difference-between-two-logs/314028 "2022-09-09T03:14:44Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Anil\_Alapati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anil_alapati/32/110660_2.png) [@Anil\_Alapati](https://discuss.elastic.co/u/Anil_Alapati)
#### Post date: [September 9, 2022, 3:14am UTC](https://discuss.elastic.co/t/time-difference-between-two-logs/314028/1 "2022-09-09T03:14:44Z")

</div>

I have two logs.

log1 is the start of the process and log2 is the end of the process. How can I get the time taken to complete the process. that is the difference between log2 and log 1.

And also I have log3 , now how do I find the time difference between log3 and log 2

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [September 9, 2022, 8:46am UTC](https://discuss.elastic.co/t/time-difference-between-two-logs/314028/2 "2022-09-09T08:46:03Z")

</div>

Hi @Anil_Alapati

welcome to the Kibana community.  
May I ask what is the structure of a document?  
Are log1, log2, log3 just different document with a single timestamp or fields of the same document ( i.e. `{log1: ..., log2: ..., log3: ... }` )?

I've often seen this type of use case where documents store a `start` and `end` timestamp value, so using a runtime script can be leveraged to compute a `duration` field.

---

<div class="post-metadata">

### Author: ![Anil\_Alapati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anil_alapati/32/110660_2.png) [@Anil\_Alapati](https://discuss.elastic.co/u/Anil_Alapati)
#### Post date: [September 9, 2022, 8:51am UTC](https://discuss.elastic.co/t/time-difference-between-two-logs/314028/3 "2022-09-09T08:51:55Z")

</div>

Hi Macro,

Thank you for the response.

each log belongs to one document.

Log1 belongs to Document 1 and log2 belongs to Document2 and log3 belongs to Document 3

I can see in every log start, that there is a @timestamp .

when I expand the document i can see two variables with the name @timestamp but both of the have the same value

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [September 9, 2022, 9:28am UTC](https://discuss.elastic.co/t/time-difference-between-two-logs/314028/4 "2022-09-09T09:28:16Z")

</div>

I see.  
If you need to compute something between two distinct document I think that [Transforming data | Elasticsearch Guide [8.4] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/transforms.html) is the best way to achieve that.  
Runtime or scripted field are able to operate only at the single document level, while aggregations won't deal with specific documents.

---

<div class="post-metadata">

### Author: ![Anil\_Alapati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anil_alapati/32/110660_2.png) [@Anil\_Alapati](https://discuss.elastic.co/u/Anil_Alapati)
#### Post date: [September 9, 2022, 9:35am UTC](https://discuss.elastic.co/t/time-difference-between-two-logs/314028/5 "2022-09-09T09:35:58Z")

</div>

Okay. Thank you. is 8.4 the new version and if i have 7.16.3 I may not be able to do right?

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [September 9, 2022, 10:06am UTC](https://discuss.elastic.co/t/time-difference-between-two-logs/314028/6 "2022-09-09T10:06:21Z")

</div>

Data transformation is available also in 7.16: [Transforming data | Elasticsearch Guide [7.16] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.16/transforms.html)

---

<div class="post-metadata">

### Author: ![Anil\_Alapati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anil_alapati/32/110660_2.png) [@Anil\_Alapati](https://discuss.elastic.co/u/Anil_Alapati)
#### Post date: [September 9, 2022, 1:11pm UTC](https://discuss.elastic.co/t/time-difference-between-two-logs/314028/7 "2022-09-09T13:11:05Z")

</div>

Hi Macro,

Thank you for the information.

Other than this document, is there any detailed explanation or sample code. to understand better with minimal knowledge on kibana?

Thank you.

---

<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: [October 7, 2022, 1:12pm UTC](https://discuss.elastic.co/t/time-difference-between-two-logs/314028/8 "2022-10-07T13:12:01Z")

</div>

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