# Count sessions from events

**URL:** <https://discuss.elastic.co/t/count-sessions-from-events/1553>\
**Category:** Kibana\
**Created:** [May 29, 2015, 11:02am UTC](https://discuss.elastic.co/t/count-sessions-from-events/1553 "2015-05-29T11:02:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FredG](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@FredG](https://discuss.elastic.co/u/FredG)\
**Post date:** [May 29, 2015, 11:02am UTC](https://discuss.elastic.co/t/count-sessions-from-events/1553/1 "2015-05-29T11:02:00Z")

</div>

Hello,

I'm rather novice in Kibana/Elasticsearch.

I have records of sessions containing two fields:

"mappings": {  
....  
"start\_date": {  
"type": "date",  
"format": "dateOptionalTime"  
},  
"end\_date": {  
"type": "date",  
"format": "dateOptionalTime"  
},  
....  
}

My purpose is to plot the number of active sessions in function of the time, that is for a given time t, the number of documents with start\_date \<= t \<= end\_date.

How can I do this ? I did not find any simple way, either using date histograms or other aggregations to do this.

Alternatively, is there a way to plot in Kibana the difference of two curves (a kind of stacked date histograms with one serving as a reference, i;e. one being set to 0).

Thank you for any hint,

Fred

---

<div class="post-metadata">

**Author:** ![Babadofar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/babadofar/32/44803_2.png) [@Babadofar](https://discuss.elastic.co/u/Babadofar)\
**Post date:** [May 29, 2015, 8:46pm UTC](https://discuss.elastic.co/t/count-sessions-from-events/1553/2 "2015-05-29T20:46:01Z")

</div>

Hi. You might have to preprocess your data to get this working at the moment.  
See this post by Mark Harwood for some ideas on how you could do this. [https://www.elastic.co/elasticon/2015/sf/building-entity-centric-indexes](https://www.elastic.co/elasticon/2015/sf/building-entity-centric-indexes)

Check out this issue on github for some hints on what the plans are for aggregations.

> <https://github.com/elastic/elasticsearch/issues/9876>
>
> There are many instances where it is useful to perform computations on the output of aggregations to calculate new aggregations. This...

---

<div class="post-metadata">

**Author:** ![FredG](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@FredG](https://discuss.elastic.co/u/FredG)\
**Post date:** [June 1, 2015, 7:46am UTC](https://discuss.elastic.co/t/count-sessions-from-events/1553/3 "2015-06-01T07:46:46Z")

</div>

Hi Christoffer,

thank you very much for your answer and for the link.

Actually, hacking the query in the date histogram panel could be an alternative to what i'm looking for ...

Fred

---

<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:18pm UTC](https://discuss.elastic.co/t/count-sessions-from-events/1553/4 "2017-07-06T14:18:49Z")

</div>


