# How to calculate between document

**URL:** <https://discuss.elastic.co/t/how-to-calculate-between-document/13713>\
**Category:** Elasticsearch\
**Created:** [September 22, 2013, 12:36pm UTC](https://discuss.elastic.co/t/how-to-calculate-between-document/13713 "2013-09-22T12:36:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiantian\_Gao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiantian_gao/32/2120_2.png) [@Tiantian\_Gao](https://discuss.elastic.co/u/Tiantian_Gao)\
**Post date:** [September 22, 2013, 12:36pm UTC](https://discuss.elastic.co/t/how-to-calculate-between-document/13713/1 "2013-09-22T12:36:34Z")

</div>

Hi experts,

A quick question: I have two type of document, the one means 'start' of  
event, the other means the 'end' of event.  
The two item of the event pair has the same 'req\_id'.

The two type of document looks like below. The same 'req\_id', one type is  
'start', the other is 'end':  
{"id": "1", "req\_id": "x", "type": "start", "timestamp": "11111"}  
{"id": "2", "req\_id": "x", "type": "end", "timestamp": "11122"}

I want to do statistic of the interval of the event pair, in this case the  
interval is 11122 - 11111 = 11.  
I have look through ElasticSearch DSL, but find nothing helpful. Maybe I  
can write client code to do the statistic,  
but I believe ElasticSearch support this kind of action.

Please let me know if I can provide more explanation. And thank you very  
mush for any suggestion.

Best regards,  
gtt

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 22, 2013, 3:03pm UTC](https://discuss.elastic.co/t/how-to-calculate-between-document/13713/2 "2013-09-22T15:03:32Z")

</div>

My guess is that you should index begin and end within the same doc, aka update doc with Id 1.

## HTH

David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 22 sept. 2013 à 14:36, Tiantian Gao [gtt116@gmail.com](mailto:gtt116@gmail.com) a écrit :

Hi experts,

A quick question: I have two type of document, the one means 'start' of event, the other means the 'end' of event.  
The two item of the event pair has the same 'req\_id'.

The two type of document looks like below. The same 'req\_id', one type is 'start', the other is 'end':  
{"id": "1", "req\_id": "x", "type": "start", "timestamp": "11111"}  
{"id": "2", "req\_id": "x", "type": "end", "timestamp": "11122"}

I want to do statistic of the interval of the event pair, in this case the interval is 11122 - 11111 = 11.  
I have look through ElasticSearch DSL, but find nothing helpful. Maybe I can write client code to do the statistic,  
but I believe ElasticSearch support this kind of action.

Please let me know if I can provide more explanation. And thank you very mush for any suggestion.

## Best regards, gtt

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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Tiantian\_Gao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiantian_gao/32/2120_2.png) [@Tiantian\_Gao](https://discuss.elastic.co/u/Tiantian_Gao)\
**Post date:** [September 22, 2013, 3:53pm UTC](https://discuss.elastic.co/t/how-to-calculate-between-document/13713/3 "2013-09-22T15:53:16Z")

</div>

Thanks David,

So I'm afraid I need write some code to update the index by myself.

cheers,  
gtt  
在 2013-9-22，下午11:03，David Pilato [david@pilato.fr](mailto:david@pilato.fr) 写道：

> My guess is that you should index begin and end within the same doc, aka update doc with Id 1.
> 
> ## HTH
> 
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 22 sept. 2013 à 14:36, Tiantian Gao [gtt116@gmail.com](mailto:gtt116@gmail.com) a écrit :
> 
> Hi experts,
> 
> A quick question: I have two type of document, the one means 'start' of event, the other means the 'end' of event.  
> The two item of the event pair has the same 'req\_id'.
> 
> The two type of document looks like below. The same 'req\_id', one type is 'start', the other is 'end':  
> {"id": "1", "req\_id": "x", "type": "start", "timestamp": "11111"}  
> {"id": "2", "req\_id": "x", "type": "end", "timestamp": "11122"}
> 
> I want to do statistic of the interval of the event pair, in this case the interval is 11122 - 11111 = 11.  
> I have look through Elasticsearch DSL, but find nothing helpful. Maybe I can write client code to do the statistic,  
> but I believe Elasticsearch support this kind of action.
> 
> Please let me know if I can provide more explanation. And thank you very mush for any suggestion.
> 
> Best regards,  
> gtt
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/XS\_bOE\_6jjk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/XS_bOE_6jjk/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
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, 2:15am UTC](https://discuss.elastic.co/t/how-to-calculate-between-document/13713/4 "2017-07-06T02:15:13Z")

</div>


