Splunk Search

How to get top 10 values of a column and its raw data for each value

anz999
Loves-to-Learn Lots

index=omi_Uat host=DEFRNCMP* sourcetype=all_events_attributes | eval {idx} = elt | fields ID,UMN,TicketID,node | top limit=10 UMN

This is the query I'm trying to get top 10 UMN . How can I get field values of ID,TicketID,node for each UMN

Tags (1)
0 Karma

dmarling
Builder

You can manually perform the top command after a stats that pulls the latest _raw event using the below query:

index=omi_Uat host=DEFRNCMP* sourcetype=all_events_attributes 
| eval {idx} = elt 
| fields ID,UMN,TicketID,node 
| stats count values(ID) as ID values(TicketID) as TicketID values(node) as node by UMN
| eventstats sum(count) as TotalCount
| eval percent=round((count/TotalCount)*100,6)
| sort 0 - count
| streamstats count as counter
| where counter<=10
| fields - TotalCount counter

If you require an other field that will make it a bit tricker, but it is possible:

index=omi_Uat host=DEFRNCMP* sourcetype=all_events_attributes 
| eval {idx} = elt 
| fields ID,UMN,TicketID,node 
| stats count values(ID) as ID values(TicketID) as TicketID values(node) as node  by UMN
| eventstats sum(count) as TotalCount
| eval percent=round((count/TotalCount)*100,6)
| sort 0 - count
| streamstats count as counter
| eval UMN=if(counter>10, UMN, "Other")
| fields - TotalCount counter
| stats sum(count) as count sum(percent) as percent values(ID) as ID values(TicketID) as TicketID values(node) as node by UMN
| sort 0 - count
If this comment/answer was helpful, please up vote it. Thank you.
0 Karma

dmarling
Builder

Sorry, I misread the initial request and the first result was providing _raw values but you wanted specific fields. I have just adjusted it for that.

If this comment/answer was helpful, please up vote it. Thank you.
0 Karma

anz999
Loves-to-Learn Lots

Thanks for your help.

0 Karma

dmarling
Builder

Glad I could help!

If this comment/answer was helpful, please up vote it. Thank you.
0 Karma

jodyfsu
Path Finder

I think you can do a join and then search again.

index=omi_Uat host=DEFRNCMP* sourcetype=all_events_attributes | eval {idx} = elt | fields ID,UMN,TicketID,node | top limit=10 UMN
| join UMN
[search index=omi_Uat host=DEFRNCMP* sourcetype=all_events_attributes | eval {idx} = elt | fields ID,UMN,TicketID,node]
| fields UMN ID TicketID node

0 Karma

anz999
Loves-to-Learn Lots

Thanks . It worked 🙂

0 Karma
Get Updates on the Splunk Community!

The Great Resilience Quest: 10th Leaderboard Update

The tenth leaderboard update (11.23-12.05) for The Great Resilience Quest is out &gt;&gt; As our brave ...

Customer Experience | Call for Stories: Your 2023 Journey with Splunk!

Share your Splunk journey: Splunk is committed to supporting our customers toward success. As the year draws ...

Infographic provides the TL;DR for the 2023 Splunk Career Impact Report

We’ve been shouting it from the rooftops! The findings from the 2023 Splunk Career Impact Report showing that ...