Splunk Search

How do I sort a timechart legend by count in decreasing order, not alphabetically?

jofish
Engager

Let's say I've got a timechart of URLs I'm serving. Over an hour, let's say I served this:

server.com/MYcats.html - 22 hits
server.com/MYdogs.html - 50 hits
server.com/MYrabbits.html - 10 hits

I would like the legend of my timechart to list those colored lines in order of number of hits:

dogs
cats
rabbits

But it sorts alphabetically. Here's [a shortened version of] my search:

index=myindex page_uri=*.html | rex field=page_uri "(?(?i)MY(\d)+)" | timechart count by animal

Can someone help? I've looked through previous answers and haven't found the right thing.

Thanks

sundareshr
Legend

Unfortunately, short of hard coding the sequence of columns, splunk will default to sort alphabetically. However, its is possible to rename the cols so they appear in the right order, like this...

   index=myindex page_uri=*.html | rex field=page_uri "(?(?i)MY(\d)+)" | timechart count by animal | untable _time animal count | eventstats sum(count) as total by animal | sort - total | delta total as d | streamstats count(eval(d!=0)) as grp | eval animal=grp."-".animial | xyseries _time animal count

This does add a number prefix to the column name.

gmorris_splunk
Splunk Employee
Splunk Employee

If you have more than 9 in the legend add the following:
| eval grp=if(len(grp)=1,"0".grp,grp)

0 Karma
Get Updates on the Splunk Community!

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!

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

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...