Splunk Search

Finding the earliest event matching a query

flaviadonno
Explorer

Hi all,
is there a quick way to find the earliest event (given the logtype and the index) matching a query ?

Tags (2)

lguinn2
Legend

Or, if you are looking for a more generic solution:

yoursearchhere
| tail 1

Why tail and not head? Because Splunk returns the search results sorted so that the latest result comes first. So the last result will be the earliest.

Other variations are possible. For example, if I want to see the earliest time that each clientip address appeared in the results, along with the count:

yoursearchhere
| stats earliest(_time) as FirstAppearance count by clientip
| fieldformat FirstAppearance=strftime(FirstAppearance,"%x %X")

flaviadonno
Explorer

Cool! Thank you!

0 Karma

kristian_kolb
Ultra Champion

If you by 'logtype' mean sourcetype;

| metadata type=sourcetypes index=your_indexname_here | convert ctime(firstTime) | fields - lastTime, recentTime, type

and yes, the search starts with a pipe (|)

/K

Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...