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!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...