# Calculating duration using timestamps from multiple documents

**URL:** <https://discuss.elastic.co/t/calculating-duration-using-timestamps-from-multiple-documents/362296>\
**Category:** Kibana\
**Created:** [July 1, 2024, 1:05pm UTC](https://discuss.elastic.co/t/calculating-duration-using-timestamps-from-multiple-documents/362296 "2024-07-01T13:05:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bjorn\_Ottenheim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bjorn_ottenheim/32/123661_2.png) [@Bjorn\_Ottenheim](https://discuss.elastic.co/u/Bjorn_Ottenheim)\
**Post date:** [July 1, 2024, 1:05pm UTC](https://discuss.elastic.co/t/calculating-duration-using-timestamps-from-multiple-documents/362296/1 "2024-07-01T13:05:43Z")

</div>

Hi..

I'm using Elastic Cloud v 8.13.2

I have a service which logs timestamps at the start and the end of the process and does that in separate documents:

For example:  
{  
"\_index": "dev-2024.06.02-000002",  
"\_id": "MPNiBpABGKUrogqmBa0B",  
"payload": {  
"@timestamp": "2024-06-11T08:19:40.777271718Z",  
"messageType": "Simple",  
"processId": "9afb1ecb-ca08-4f1f-8dcf-380e01f9c193",  
"status": "START",  
"service": "submission",  
}  
},  
{  
"\_index": "dev-2024.06.02-000002",  
"\_id": "MPNiBpABGKUrogqmBa0B",  
"payload": {  
"@timestamp": "2024-06-11T08:19:41.777271718Z",  
"messageType": "Simple",  
"processId": "9afb1ecb-ca08-4f1f-8dcf-380e01f9c193",  
"status": "FINISH",  
"service": "submission",  
}  
}

I want to visualize the duration of the processstep.  
The logic is:  
agggregate on payload.processId and payload.service  
duration = payload.@timestamp where status=FINISH - payload.@timestamp where status=START

I tried a number of things but i didn't get it to work yet.  
I created a DSL that calculates the duration but i can'not use it in a visualisation.

I created a Data table visualisation:  
Create bucket on payload.processId.keyword  
Add sub-bucket Split Row on payload.service.keyword  
Added Mertics start\_time and finish\_time.  
These show up in the table nicely.  
But can't find a way to calculate and show the duration.

Can one of you please help me out and provide a solution?  
Thanks for you help.
