Splunk Search

How to limit results with multiple group by conditions?

alchang
Explorer

Can the limit command be used with multiple conditions?

My search query is as follows | stats count as num by searchTerm, domain. I want to return the top 3 searchterms per domain. Is there a way to do that from the search bar in splunk UI?

Desired Output:

Domain searchTerm Number
Google ABC 100
Google DEF 50
Google GHI 25
Yahoo DEF 75
Yahoo ABC 60
Yahoo JKL 20
Bing DEF 80
Bing JKL 40
Bing GHI 20

Tags (3)
0 Karma

MuS
Legend

Hi alchang,

try something like this:

your base search here 
| stats count as num by searchTerm, domain
| sort domain, -num 
| streamstats num as rank by domain
| where rank < 4

Hope this helps to get you started ...

cheers, MuS

alchang
Explorer

Thanks! That worked. I hadn't worked much with streamstats before, but it looks very powerful. I will check it out. Offhand, do you know if streamstats works with report acceleration?

0 Karma

MuS
Legend

According to the docs http://docs.splunk.com/Documentation/Splunk/6.2.1/Report/Acceleratereports#How_reports_qualify_for_r... only transforming commands qualify for report acceleration. Find a list of transforming commands here http://docs.splunk.com/Splexicon:Transformingcommand

Feel free to accept this answer if it answered your question - you get some kudos as well 😉

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...