# Date with the max count grouped by a term

**URL:** <https://discuss.elastic.co/t/date-with-the-max-count-grouped-by-a-term/307377>\
**Category:** Kibana\
**Created:** [June 16, 2022, 10:00am UTC](https://discuss.elastic.co/t/date-with-the-max-count-grouped-by-a-term/307377 "2022-06-16T10:00:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crimson589](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@crimson589](https://discuss.elastic.co/u/crimson589)\
**Post date:** [June 16, 2022, 10:00am UTC](https://discuss.elastic.co/t/date-with-the-max-count-grouped-by-a-term/307377/1 "2022-06-16T10:00:43Z")

</div>

I'm currently getting this results

message1 | 2022-06-09 | 250  
message1 | 2022-06-08 | 300  
message2 | 2022-06-09 | 400  
message2 | 2022-06-08 | 200

And my current setting is like this

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/2/02cd3d2f93438543f4c76962fe1ba4b9549a4f32.png)

What do I need to add here to just get the dates with the highest count like tis

message1 | 2022-06-08 | 300  
message2 | 2022-06-09 | 400

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [June 17, 2022, 8:40pm UTC](https://discuss.elastic.co/t/date-with-the-max-count-grouped-by-a-term/307377/2 "2022-06-17T20:40:11Z")

</div>

Hello,

So your interval is daily and you are seeing results for that. I am not sure how to tweak this? I will buzz you back.

Thanks,  
Bhavya

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [June 20, 2022, 8:43am UTC](https://discuss.elastic.co/t/date-with-the-max-count-grouped-by-a-term/307377/3 "2022-06-20T08:43:06Z")

</div>

There is no such function to filter date histogram buckets.

One option is to create a [runtime field](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-retrieving-fields.html) to calculate the date of `@timestamp` and then use terms aggregation with size 1 on that runtime field.

---

<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 18, 2022, 8:43am UTC](https://discuss.elastic.co/t/date-with-the-max-count-grouped-by-a-term/307377/4 "2022-07-18T08:43:54Z")

</div>

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