Splunk Search

How to return a group by value with the highest number of items?

jbrenner
Path Finder

How do I modify the following query to return the name of the FRUIT with the highest count:

index="myindex" URI="myuri" | stats count by FRUIT

Thanks,
Jonathan

Tags (2)
0 Karma
1 Solution

493669
Super Champion

Try this:

index="myindex" URI="myuri" | stats count by FRUIT|stats max(count) as max

View solution in original post

0 Karma

somesoni2
Revered Legend

You can do like this

index="myindex" URI="myuri" | top 1 FRUIT

This will give you name of top 1 FRUIT based on event count. You can adjust the number in top command to return more

0 Karma

jbrenner
Path Finder

Hi somesoni2,

That is perfect, thanks!

Now how could I modify your query to return the fruit name concatenated to the count in a single string like so:

 apple:2013

Thanks,
Jonathan

0 Karma

somesoni2
Revered Legend

A simple eval statement will do that

above search | eval FRUIT=FRUIT.":".count 
0 Karma

493669
Super Champion

Try this:

index="myindex" URI="myuri" | stats count by FRUIT|stats max(count) as max
0 Karma

jbrenner
Path Finder

That gives me the count, but I want to return the name of the fruit.

Thanks,
Jonathan

0 Karma

493669
Super Champion

ok then try this it will give max count with name of fruit:

index="myindex" URI="myuri" | stats count by FRUIT|stats max(count) as max by FRUIT|head 1
0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...