Splunk Search

How do you list top items for each group?

peterlandis
Explorer

I want to list the top 3 elements for each group. How would you do this?

Examples
Name score
Jon 100
Jon 54
Jon 90
Jon 72
Jon 87
Jane 89
Jane 99
Jane 66
Jane 56
Jane 100

Show the top 3 scores for each person?

Name score
Jon 100
Jon 90
Jon 87
Jane 100
Jane 99
Jane 89

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

... | sort 0 Name -score | dedup 3 Name

View solution in original post

peterlandis
Explorer

Thanks! That worked and that was a really fast response. Very impressed with this community. Thanks splunkers!

0 Karma

peterlandis
Explorer

Thanks! That worked and that was a really fast response. Very impressed with this community. Thanks splunkers!

0 Karma

lfedak_splunk
Splunk Employee
Splunk Employee

Hey @peterlandis, Welcome to the Answers community! @cmerriman and @woodcock are awesome and super helpful. You can accept one of the answers and upvote the second if both worked for you. (You can actually upvote both as well.) This helps others use the answer in the future and awards everyone karma points. 🙂

woodcock
Esteemed Legend

Like this:

... | sort 0 Name -score | dedup 3 Name

arusoft
Communicator

@woodcock I know this is an old thread, but I had similar requirement. Is it possible that this can be done without doing dedup ?

Is dedup not costly? 

 

Thank You.

0 Karma

PickleRick
SplunkTrust
SplunkTrust
0 Karma

peterlandis
Explorer

Thanks! This worked perfectly. Appreciate the quick response.

0 Karma

peterlandis
Explorer

Just curious why sort 0. What does 0 do?

0 Karma

woodcock
Esteemed Legend

It makes it unlimited, otherwise it limits to 10K. Be sure to click Accept to close the question.

0 Karma

cmerriman
Super Champion

0 essentially means there is no limit to how many events will be sorted. otherwise there is a default limit of 10000

http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Sort

0 Karma

cmerriman
Super Champion

something like this should work ...|sort 0 Name - score|streamstats count by Name|search count<4|fields - count

Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...