# Find most frequent users on basis of captureTime

**URL:** <https://discuss.elastic.co/t/find-most-frequent-users-on-basis-of-capturetime/180015>\
**Category:** Elasticsearch\
**Created:** [May 7, 2019, 3:35pm UTC](https://discuss.elastic.co/t/find-most-frequent-users-on-basis-of-capturetime/180015 "2019-05-07T15:35:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rashmi\_Nagpal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi_nagpal/32/42172_2.png) [@Rashmi\_Nagpal](https://discuss.elastic.co/u/Rashmi_Nagpal)\
**Post date:** [May 7, 2019, 3:35pm UTC](https://discuss.elastic.co/t/find-most-frequent-users-on-basis-of-capturetime/180015/1 "2019-05-07T15:35:51Z")

</div>

I want to fire a query, which should return most frequent users data on the basis of attribute - "CaptureTime", which is an array of variable sizes[of timestamp field].  
I can't perform "update by query" because of some restrictions, so, I tried to perform max using aggregation API but remained unsuccessful, also thought if I can sort in decreasing order on the "CaptureTime" array length which will help me in finding - most frequent users.  
Below is the glimpse of that dataset :-

> {  
> "\_source" : {  
> id : "23",  
> captureTime :  
> ["2019-05-03T16:17",  
> "2019-05-03T16:18",  
> "2019-05-03T16:39",  
> "2019-05-03T16:40"]  
> },  
> "\_source" : {  
> "empid":"45",  
> "captureTime":  
> ["2019-04-29T10:54",  
> "2019-04-29T10:59",  
> "2019-04-29T11:02",  
> "2019-04-29T11:23",  
> "2019-04-29T11:32",  
> "2019-04-29T11:33"]  
> }  
> }

Kindly provide me some insights.Thanks a real bunch!

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 10, 2019, 3:52pm UTC](https://discuss.elastic.co/t/find-most-frequent-users-on-basis-of-capturetime/180015/2 "2019-05-10T15:52:39Z")

</div>

I think a `date_histogram` aggregation on `captureTime`, followed by a `terms` aggregation on ID would work.

That will give you a bucket per time interval (every five minutes, or whatever makes sense). Then for each bucket of time, the `terms` agg will give you the list of IDs that fell into that bucket.

---

<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:** [June 7, 2019, 3:52pm UTC](https://discuss.elastic.co/t/find-most-frequent-users-on-basis-of-capturetime/180015/3 "2019-06-07T15:52:44Z")

</div>

Closed on June 7, 2019, 3:52pm UTC

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