# How to create query which can calculate time difference?

**URL:** <https://discuss.elastic.co/t/how-to-create-query-which-can-calculate-time-difference/15919>\
**Category:** Elasticsearch\
**Created:** [February 20, 2014, 8:48am UTC](https://discuss.elastic.co/t/how-to-create-query-which-can-calculate-time-difference/15919 "2014-02-20T08:48:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Filip\_Golonka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/filip_golonka/32/1805_2.png) [@Filip\_Golonka](https://discuss.elastic.co/u/Filip_Golonka)\
**Post date:** [February 20, 2014, 8:48am UTC](https://discuss.elastic.co/t/how-to-create-query-which-can-calculate-time-difference/15919/1 "2014-02-20T08:48:07Z")

</div>

I have and index with following documents:

{name: 'Device1', type: 'start', 'eventTime': '2013-02-19 12:00:00'}  
{name: 'Device2', type: 'start', 'eventTime': '2013-02-19 12:02:00'}  
{name: 'Device1', type: 'stop', 'eventTime': '2013-02-19 12:45:00'}  
{name: 'Device2', type: 'stop', 'eventTime': '2013-02-19 12:50:00'}

I would like to create a query which will return for me a new field with  
time differences between eventTime's, faceted by device name and regards  
with field type. For the example it should be:

{name: 'Device1', 'type': 'it really doesnt matter', eventTime: 'also doesnt matter', duration: '00:45:00'}  
{name 'Device2', 'type': 'it really doesnt matter', eventTime: 'also doesnt matter', duration: '00:48:00'}

Is it possible with elastic search query language?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/80b1727a-5ee6-4897-8ab4-de95d8a01b82%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/80b1727a-5ee6-4897-8ab4-de95d8a01b82%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 1:48am UTC](https://discuss.elastic.co/t/how-to-create-query-which-can-calculate-time-difference/15919/2 "2017-07-06T01:48:50Z")

</div>


