# Query to get the difference of datetime of two records in elasticsearch

**URL:** <https://discuss.elastic.co/t/query-to-get-the-difference-of-datetime-of-two-records-in-elasticsearch/40527>\
**Category:** Elasticsearch\
**Created:** [January 29, 2016, 10:16pm UTC](https://discuss.elastic.co/t/query-to-get-the-difference-of-datetime-of-two-records-in-elasticsearch/40527 "2016-01-29T22:16:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fan\_Yang](https://avatars.discourse-cdn.com/v4/letter/f/9fc348/32.png) [@Fan\_Yang](https://discuss.elastic.co/u/Fan_Yang)\
**Post date:** [January 29, 2016, 10:16pm UTC](https://discuss.elastic.co/t/query-to-get-the-difference-of-datetime-of-two-records-in-elasticsearch/40527/1 "2016-01-29T22:16:56Z")

</div>

I have following Json records in Elasticsearch:  
{  
"endpoint": "bulk",  
"application": "Interface",  
**"message": "Request finished",**  
"@version": "1",  
**"requestId": 18714,**  
"@timestamp": "2016-01-29T20:22:43.684Z",  
},  
"fields": {  
"@timestamp": [  
1454098963684  
]  
}  
}

{  
"endpoint": "bulk",  
"application": "Interface",  
**"message": "Issuing Request",**  
"@version": "1",  
**"requestId": 18714,**  
"@timestamp": "2016-01-29T20:22:43.411Z",  
},  
"fields": {  
"@timestamp": [  
1454098963411  
]  
}  
}

How should i write the query which can subtract the timestamps of "requestID=x issuing request" to "requestID=x request finished"?

---

<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:** [July 5, 2017, 11:20pm UTC](https://discuss.elastic.co/t/query-to-get-the-difference-of-datetime-of-two-records-in-elasticsearch/40527/2 "2017-07-05T23:20:16Z")

</div>


