Splunk Enterprise

help to sort _time

jip31
Motivator

hi

why my sort _time doesnt works please?

what is strange is that when I click directly on the field the sort doesnt works too

 

| eval _time = strftime(_time, "%d-%m-%y %H:%M:%S") 
| sort _time 
| stats last(host) as host, last(os) as OS by _time 
| rename host as Host, _time as Date 
| table Date, Host, OS
| sort - Date

 

Tags (1)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

_time is internally stored as a number. It is a number of seconds since 1.01.1970.

If the field is called _time it's rendered in the UI as a string in your local timezone. (you can check it by doing

| eval mytime=_time

Since it's a number, you can normalky manipulate it (add or substract time to/from it) or sort it.

If you render it to text as you did in your example, you operate on strings and splunk doesn't understand that it's supposed to be a date. For splunk it's a normal string so if you sort by this field it sorts lexicographicallh which is definitelly not what you want.

So, to sum up - don't strftime your time fields if you want to do anything with them. If you want them to be shown in a particular way in webui, use fieldformat, not eval.

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

_time is internally stored as a number. It is a number of seconds since 1.01.1970.

If the field is called _time it's rendered in the UI as a string in your local timezone. (you can check it by doing

| eval mytime=_time

Since it's a number, you can normalky manipulate it (add or substract time to/from it) or sort it.

If you render it to text as you did in your example, you operate on strings and splunk doesn't understand that it's supposed to be a date. For splunk it's a normal string so if you sort by this field it sorts lexicographicallh which is definitelly not what you want.

So, to sum up - don't strftime your time fields if you want to do anything with them. If you want them to be shown in a particular way in webui, use fieldformat, not eval.

venkatasri
SplunkTrust
SplunkTrust

Hi @jip31 

you could possibly hitting with these,

sort command having 10K limit see if you are hitting the limit and

when you rename _time to Date it converts to epoch.. 

you are sorting | sort _time which means shows oldest on top, and again at the end | sort Date which is an epoch bring the latest events to top. check your | stats command to by _time with last() func might not give you correct context.

--

Appreciate an upvote if this helps!

0 Karma

venkatasri
SplunkTrust
SplunkTrust
| sort 0 _time

This won't hit the 10k limit.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...