Splunk Search

Using a result from one search in another search

htkhtk
Path Finder

I am trying to:

  1. Find a date/time of a certain event.
  2. Take that date/time from number 1. and use it to search for events only from that date/time forward.

If the date/time from number 1 was September 1st at 1:45.. Then for number 2, I would only want to get back events from September 1st and forward (forgetting about events before that.)

I need this to be automatic in the searches because the date/time range from number 1 will change based upon different circumstances.

I tried subsearches to no avail.

I am using _time.

Thanks in advance!

0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

This should pretty much be it:

sourcetype=outer [ sourcetype=inner item=xxxx | head 1 | rename _time as earliest | fields earliest ]

I use head 1 to ensure just a single result, but if you only get one result some other way, that's fine too.

View solution in original post

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

This should pretty much be it:

sourcetype=outer [ sourcetype=inner item=xxxx | head 1 | rename _time as earliest | fields earliest ]

I use head 1 to ensure just a single result, but if you only get one result some other way, that's fine too.

0 Karma

dennywebb
Path Finder

Is there a way to do this same thing... but for multiple results? like if i wanted to show a table full of IP stats/etc limited to the top 10 IP values of only 1 of those stats? or in this example, the earliest 10?

0 Karma

htkhtk
Path Finder

This is exactly what i wanted.. thanks!

0 Karma

jrodman
Splunk Employee
Splunk Employee

Yeah if you just want to bound, rather than get exact second, this is better.

0 Karma

jrodman
Splunk Employee
Splunk Employee

This is pattern is possible using a subsearch, with kind of hack of a special field called 'search', mentioned over here:

http://answers.splunk.com/questions/3471/using-a-subsearch-to-get-the-time-of-an-event

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

you can't use a subsearch with the where command. Please see my other answer.

0 Karma

jrodman
Splunk Employee
Splunk Employee

In the example given, there would be no where clause. It simply becomes a constraint on the base search, which is vastly more performant. The base search command can and does perform numerical equality testing as well as numerical comparisons.

0 Karma

htkhtk
Path Finder

I have gotten that far but when I try to do the where _time > [that sub search here].. It doesn't work or sometimes i get an error that says the values aren't compatible

0 Karma
Get Updates on the Splunk Community!

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 ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...