Splunk Search

How can I use the output from a previous search to use as a time range on my next search?

norbertkiammacl
Explorer

I have a filter that extracts the date and time just like below.

index=_server _raw="*completed*" | head 1 | eval end_time=strftime(max(_time), "%m/%d/%Y:%H:%M:%S")

But I would like to have another search that uses the date/time I got from the first search to my second search something like the below.

index=_server _raw="*completed*" | head 1 | eval end_time=strftime(max(_time), "%m/%d/%Y:%H:%M:%S") | append [search index=_server | where _time < end_time]
0 Karma
1 Solution

javiergn
SplunkTrust
SplunkTrust

I can't test the following on a Splunk instance right now, but what about the other way around and using subsearches and "latest" instead:

index=_server  [ |search index=_server _raw="completed" | head 1 | rename _time as latest | return latest ]

View solution in original post

javiergn
SplunkTrust
SplunkTrust

I can't test the following on a Splunk instance right now, but what about the other way around and using subsearches and "latest" instead:

index=_server  [ |search index=_server _raw="completed" | head 1 | rename _time as latest | return latest ]

norbertkiammacl
Explorer

Exactly what I need, 'return' is the key. Cheers!

0 Karma

emaccaferri
Communicator

I think you could use your search that identifies the end_time as in this example http://docs.splunk.com/Documentation/Splunk/6.1.2/SearchTutorial/Useasubsearch

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...