# Comparing multiple timestamp fields

**URL:** <https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551>\
**Category:** Elasticsearch\
**Created:** [November 4, 2014, 5:00am UTC](https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551 "2014-11-04T05:00:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijay\_karmani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijay_karmani/32/1127_2.png) [@vijay\_karmani](https://discuss.elastic.co/u/vijay_karmani)\
**Post date:** [November 4, 2014, 5:00am UTC](https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551/1 "2014-11-04T05:00:09Z")

</div>

I've document structure like

{  
username : abc  
login\_timestamp : 2014-04-11 11:05:00 AM  
logout\_timestamp : 2014-04-11 11:30:00 AM  
},

{  
username : def  
login\_timestamp : 2014-04-11 11:15:00 AM  
logout\_timestamp : 2014-04-11 11:45:00 AM  
} ,

{  
username : xyz  
login\_timestamp : 2014-04-11 12:10:00 PM  
logout\_timestamp : 2014-04-11 01:15:00 PM  
}

I would like to calculate number of concurrent user sessions for a given  
date. For example if login\_timestamp/logout\_timestamp of one user overlaps  
with login\_timestamp/logout\_timestamp of other user then they are said to  
have concurrent session and in above example, users _abc_ and _def_ are  
having concurrent sessions. Hence output should have 2 against 2014-04-11  
date.

Is it possible in es and if so then can anybody help to form a query for  
this?

Thanks  
Vijay

--  
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/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vijay\_karmani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijay_karmani/32/1127_2.png) [@vijay\_karmani](https://discuss.elastic.co/u/vijay_karmani)\
**Post date:** [November 5, 2014, 6:57am UTC](https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551/2 "2014-11-05T06:57:51Z")

</div>

anybody for any help please?

On Tuesday, November 4, 2014 10:30:09 AM UTC+5:30, vijay karmani wrote:

> I've document structure like
> 
> {  
> username : abc  
> login\_timestamp : 2014-04-11 11:05:00 AM  
> logout\_timestamp : 2014-04-11 11:30:00 AM  
> },
> 
> {  
> username : def  
> login\_timestamp : 2014-04-11 11:15:00 AM  
> logout\_timestamp : 2014-04-11 11:45:00 AM  
> } ,
> 
> {  
> username : xyz  
> login\_timestamp : 2014-04-11 12:10:00 PM  
> logout\_timestamp : 2014-04-11 01:15:00 PM  
> }
> 
> I would like to calculate number of concurrent user sessions for a given  
> date. For example if login\_timestamp/logout\_timestamp of one user overlaps  
> with login\_timestamp/logout\_timestamp of other user then they are said to  
> have concurrent session and in above example, users _abc_ and _def_ are  
> having concurrent sessions. Hence output should have 2 against 2014-04-11  
> date.
> 
> Is it possible in es and if so then can anybody help to form a query for  
> this?
> 
> Thanks  
> Vijay

--  
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/f3f2d1d1-b051-4678-a2d4-b82832fbc877%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f3f2d1d1-b051-4678-a2d4-b82832fbc877%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vijay\_karmani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijay_karmani/32/1127_2.png) [@vijay\_karmani](https://discuss.elastic.co/u/vijay_karmani)\
**Post date:** [November 5, 2014, 6:59am UTC](https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551/3 "2014-11-05T06:59:39Z")

</div>

anybody for any help please?

--  
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/4946d7aa-278f-46e4-976c-f7bd9e4ba88f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4946d7aa-278f-46e4-976c-f7bd9e4ba88f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vijay\_karmani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijay_karmani/32/1127_2.png) [@vijay\_karmani](https://discuss.elastic.co/u/vijay_karmani)\
**Post date:** [November 6, 2014, 9:10am UTC](https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551/4 "2014-11-06T09:10:38Z")

</div>

anybody for any help please?

On Wednesday, November 5, 2014 12:29:39 PM UTC+5:30, vijay karmani wrote:

> anybody for any help please?

--  
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/1c38cafc-6f72-4ad4-a189-4e5050187da4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c38cafc-6f72-4ad4-a189-4e5050187da4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [November 6, 2014, 9:54am UTC](https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551/5 "2014-11-06T09:54:17Z")

</div>

Helli Vijay ,

I cant think of any straight and efficient way to implement this.  
But then you can write your own map reduce script ( Feature in 1.4.0) to  
gather this information -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Thanks  
Vineeth

On Tue, Nov 4, 2014 at 10:30 AM, vijay karmani [vijay.karmani@gmail.com](mailto:vijay.karmani@gmail.com)  
wrote:

> I've document structure like
> 
> {  
> username : abc  
> login\_timestamp : 2014-04-11 11:05:00 AM  
> logout\_timestamp : 2014-04-11 11:30:00 AM  
> },
> 
> {  
> username : def  
> login\_timestamp : 2014-04-11 11:15:00 AM  
> logout\_timestamp : 2014-04-11 11:45:00 AM  
> } ,
> 
> {  
> username : xyz  
> login\_timestamp : 2014-04-11 12:10:00 PM  
> logout\_timestamp : 2014-04-11 01:15:00 PM  
> }
> 
> I would like to calculate number of concurrent user sessions for a given  
> date. For example if login\_timestamp/logout\_timestamp of one user overlaps  
> with login\_timestamp/logout\_timestamp of other user then they are said to  
> have concurrent session and in above example, users _abc_ and _def_ are  
> having concurrent sessions. Hence output should have 2 against 2014-04-11  
> date.
> 
> Is it possible in es and if so then can anybody help to form a query for  
> this?
> 
> Thanks  
> Vijay
> 
> --  
> 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/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGdPd5mNDbU\_C7Qo00TYW5qNg7qdepnJbKprp9eWTX\_pNu%3DS\_g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mNDbU_C7Qo00TYW5qNg7qdepnJbKprp9eWTX_pNu%3DS_g%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vijay\_karmani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijay_karmani/32/1127_2.png) [@vijay\_karmani](https://discuss.elastic.co/u/vijay_karmani)\
**Post date:** [November 6, 2014, 12:21pm UTC](https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551/6 "2014-11-06T12:21:40Z")

</div>

Thanks Vineeth for your answer. I will give it a shot.

On Thursday, November 6, 2014 3:24:28 PM UTC+5:30, vineeth mohan wrote:

> Helli Vijay ,
> 
> I cant think of any straight and efficient way to implement this.  
> But then you can write your own map reduce script ( Feature in 1.4.0) to  
> gather this information -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html)
> 
> Thanks  
> Vineeth
> 
> On Tue, Nov 4, 2014 at 10:30 AM, vijay karmani \<[vijay....@gmail.com](mailto:vijay....@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > I've document structure like
> > 
> > {  
> > username : abc  
> > login\_timestamp : 2014-04-11 11:05:00 AM  
> > logout\_timestamp : 2014-04-11 11:30:00 AM  
> > },
> > 
> > {  
> > username : def  
> > login\_timestamp : 2014-04-11 11:15:00 AM  
> > logout\_timestamp : 2014-04-11 11:45:00 AM  
> > } ,
> > 
> > {  
> > username : xyz  
> > login\_timestamp : 2014-04-11 12:10:00 PM  
> > logout\_timestamp : 2014-04-11 01:15:00 PM  
> > }
> > 
> > I would like to calculate number of concurrent user sessions for a given  
> > date. For example if login\_timestamp/logout\_timestamp of one user overlaps  
> > with login\_timestamp/logout\_timestamp of other user then they are said to  
> > have concurrent session and in above example, users _abc_ and _def_ are  
> > having concurrent sessions. Hence output should have 2 against 2014-04-11  
> > date.
> > 
> > Is it possible in es and if so then can anybody help to form a query for  
> > this?
> > 
> > Thanks  
> > Vijay
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/84a9e732-5f1b-4480-ab55-e95789813d6f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/4d2bad52-85cc-4f33-a67b-81235d42bf4e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4d2bad52-85cc-4f33-a67b-81235d42bf4e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Hornov](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@Hornov](https://discuss.elastic.co/u/Hornov)\
**Post date:** [January 14, 2016, 2:38pm UTC](https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551/7 "2016-01-14T14:38:39Z")

</div>

I've the same need and I havn't found how map reduce script can help. Have you found a solution ?  
Thanks.

---

<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:24pm UTC](https://discuss.elastic.co/t/comparing-multiple-timestamp-fields/20551/8 "2017-07-05T23:24:28Z")

</div>


