Splunk Search

sort by Time desc

shangshin
Builder

Hi, I tried to format the eventtime and would like to show the latest time event first. However, the search string below always displays the oldest event first, What's even weird is that when I clicked on the Time header in the table, the column is still not sorted. I am wondering if anyone can shed some light on this? Thank you!

| bucket _time span=60m | eval Time=strftime(_time, "%m/%d %H:%M %Z") | STATS avg(time_taken) AS AverageResponseTime BY Time | sort by Time desc

Tags (2)
1 Solution

Ayn
Legend

Your syntax is a little off. Have a look at sort's syntax here: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Sort

This should work better:

... | sort - Time

View solution in original post

gblock_splunk
Splunk Employee
Splunk Employee

If you are trying to sort by the extracted timestamp, then _time is what you want to use i.e.

| sort -_time

I just hit this and it was driving me nuts as I was using Time and not seeing the expected result.

Ayn
Legend

Your syntax is a little off. Have a look at sort's syntax here: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Sort

This should work better:

... | sort - Time

evanriegel
New Member

Hi there, this answer isn't working for me. Here's the query I'm typing:

name@email.com | sort - Time

And in the output I'm seeing:

Time
5/2/19 7:38:41.000 PM
5/2/19 7:38:44.769 PM
5/2/19 7:38:44.000 PM

So, not only is the order not descending, but it's not even sorted. Splunk is ignoring my sort directive altogether and is just doing whatever it wants instead.

Please advise?
Thanks

0 Karma

shangshin
Builder

Thank you.

0 Karma

dmorozov
New Member

Hello, it doesn't seems to work for me 😞
The source type is log4j logs. Splunk (light) successfully parsed date/time and shows me separate column in search results with name "Time". I tried (with space and without space after minus):
| sort -Time
| sort -_time

Whatever I do it just ignore and sort results ascending.
I figured out that if I put wrong field name it does the same. The name "_time" I tried to use because when you click on the value in Time column it shows option to show events before or auto and tell me that the field name is "_time". Could you make any suggestion please?

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...