# How to calculate the overlap / elapsed time range in elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-calculate-the-overlap-elapsed-time-range-in-elasticsearch/108301>\
**Category:** Elasticsearch\
**Created:** [November 19, 2017, 11:44pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-overlap-elapsed-time-range-in-elasticsearch/108301 "2017-11-19T23:44:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![betimer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/betimer/32/20930_2.png) [@betimer](https://discuss.elastic.co/u/betimer)\
**Post date:** [November 19, 2017, 11:44pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-overlap-elapsed-time-range-in-elasticsearch/108301/1 "2017-11-19T23:44:39Z")

</div>

Hi,

I have around million records in ES, they are different online meeting records that people join/leave at the different time.

```
{name:"p1", join:'2017-11-17T00:01:00.293Z', leave: "2017-11-17T00:06:00.293Z"}
{name:"p2", join:'2017-11-17T00:02:00.293Z', leave: "2017-11-17T00:04:00.293Z"}
{name:"p3", join:'2017-11-17T00:03:00.293Z', leave: "2017-11-17T00:05:00.293Z"}

```

Time range could be something like this:

```
 p1: [=========================]
 p2: [==========]
 p3: [==========]

```

The question is how to calculate the overlap time range happened last month, the example one should be **3 min** , but I need to calculate the whole month different meetings

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [November 21, 2017, 2:22pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-overlap-elapsed-time-range-in-elasticsearch/108301/2 "2017-11-21T14:22:56Z")

</div>

You could do a max aggregation on the join time, a min aggregation on the leave time and compute the difference between those two values on client-side.

---

<div class="post-metadata">

**Author:** ![betimer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/betimer/32/20930_2.png) [@betimer](https://discuss.elastic.co/u/betimer)\
**Post date:** [November 22, 2017, 1:28am UTC](https://discuss.elastic.co/t/how-to-calculate-the-overlap-elapsed-time-range-in-elasticsearch/108301/3 "2017-11-22T01:28:59Z")

</div>

@jpountz Thank you for that, but I need to get the result for the whole long period (e.g. a week/month) instead of single meeting call. Do you have any good idea to address that?

---

<div class="post-metadata">

**Author:** ![joconner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joconner/32/24360_2.png) [@joconner](https://discuss.elastic.co/u/joconner)\
**Post date:** [November 22, 2017, 2:58am UTC](https://discuss.elastic.co/t/how-to-calculate-the-overlap-elapsed-time-range-in-elasticsearch/108301/4 "2017-11-22T02:58:34Z")

</div>

Is there no unique meeting id associated with these joins and leaves? Is it just one regularly scheduled meeting?

---

<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:** [December 20, 2017, 2:58am UTC](https://discuss.elastic.co/t/how-to-calculate-the-overlap-elapsed-time-range-in-elasticsearch/108301/5 "2017-12-20T02:58:43Z")

</div>

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