# Group by and having max field

**URL:** <https://discuss.elastic.co/t/group-by-and-having-max-field/300519>\
**Category:** Kibana\
**Created:** [March 24, 2022, 6:07am UTC](https://discuss.elastic.co/t/group-by-and-having-max-field/300519 "2022-03-24T06:07:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brknlpr](https://avatars.discourse-cdn.com/v4/letter/b/8e7dd6/32.png) [@brknlpr](https://discuss.elastic.co/u/brknlpr)\
**Post date:** [March 24, 2022, 6:07am UTC](https://discuss.elastic.co/t/group-by-and-having-max-field/300519/1 "2022-03-24T06:07:22Z")

</div>

Hi I have a data in kibana as below

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/0/40940a14b61d93c0fadeaaba78a0731760c165a3.png)  
What I am trying to do is to get the only journeyId.keyword 's which has max IndexInEntry

for example this is the response I want to get  
c4ca5cfaedbfa3f6de4feb1590002c50 3  
c9f6ddd6aa84641571f4cf8a02374d7c 5  
d94eed3c8d138c4588ea4ff8cb1f0ce0 5  
.  
.  
.  
Is there a way to do it with kql ?  
Also I am trying to do it by writing some filtering but couldnt make it.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/0/5077a9327183fe3c7960abae29f06286502e5ec9.png)

also this query dsl is not accepting

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/c/ac5f41e2e24ab91109c8ca18e8e8de8f95bbba8a.png)

would be happy if I can get an idea about how to achieve this thanks in advance!

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [March 24, 2022, 10:52am UTC](https://discuss.elastic.co/t/group-by-and-having-max-field/300519/2 "2022-03-24T10:52:24Z")

</div>

Hello,  
yes, you can achieve it, but you need a tool for aggregating your data. Discover won't work here. Do you need an exact timestamp or only Id and max IndexInEntry? For example, solution in Lens: (Replace customer\_id by JourneyId.keyword and products.base\_price by IndexInEntry).

 ![Screenshot 2022-03-24 at 11.50.29](https://us1.discourse-cdn.com/elastic/original/3X/4/0/40d947b2bf5cfd293b44ebccbcb9569479d7486f.png)

If you need to also display a timestamp, that unfortunately is not possible here.

---

<div class="post-metadata">

**Author:** ![brknlpr](https://avatars.discourse-cdn.com/v4/letter/b/8e7dd6/32.png) [@brknlpr](https://discuss.elastic.co/u/brknlpr)\
**Post date:** [March 25, 2022, 6:05am UTC](https://discuss.elastic.co/t/group-by-and-having-max-field/300519/3 "2022-03-25T06:05:20Z")

</div>

thanks for the answer Marta but yes I want not only timestamp but also other fields that doesnt exist in the ss :(. I want to visualize those information thats why I need to filter them as I want first but seems no chance.

---

<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:** [April 22, 2022, 6:06am UTC](https://discuss.elastic.co/t/group-by-and-having-max-field/300519/4 "2022-04-22T06:06:20Z")

</div>

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