Using the Splunk query language how would be a splunk query that returns the Top 1 from a set of Top N?
Data set sample:
time Term count
2014-03-28 10:00 hello 10
2014-03-28 10:00 ciao 9
2014-03-28 10:00 nice 7
2014-03-28 11:00 nice 11
2014-03-28 11:00 great 8
2014-03-28 11:00 precise 6
2014-03-28 12:00 yougotit 6
2014-03-28 12:00 ok 4
2014-03-28 12:00 thanks 3
The splunk query should return the top 1 of each Top N set. Example:
time Term count
2014-03-28 10:00 hello 10
2014-03-28 11:00 nice 11
2014-03-28 12:00 yougotit 6
Thanks,
Lp
My solution:
After reading the suggestions provided in below answers,I took the following approach:
1) Create a summary index.
2) Create an hourly schedule search to get the Top N and store the results in the summary index. Splunk query:
index="my_raw_index" |eval time=strftime(_time, "%m/%d/%Y:%H:%M") |
top limit=0 term by time|streamstats count as rank|table time term count
Result set:
time rank Term count
2014-03-28 10:00 1 hello 10
2014-03-28 10:00 2 nice 11
2014-03-28 10:00 3 yougotit 6
3) Then, by using the rank field, it is quite simple to get the Top 1 from the set of Top N result set from the summary index. Query example:
index=my_summary_index rank=1|table time Term count.
I think this approach would scale quite well.
Thanks,
Lp
... View more