Splunk Search

Subsearch Realtime - Parent Search Last 5 minutes

BP9906
Builder

Is it possible to have a subsearch looking for a log entry in realtime, then take that field and look back the past 5 minutes for the web logs?

I cant seem to get a subsearch to work properly because it does both the subsearch and parent search in realtime, which is why I get no results.

Example:

index=weblog [ search index=log AND "keyword" | fields + field_name ]

Tags (2)
0 Karma

sowings
Splunk Employee
Splunk Employee

You can use the earliest and latest keywords in a search (before the first pipe (|) character) to guide Splunk and constrain one part of the search, thereby ignoring the time range picker. Hints on the format of these "earliest" and "latest" modifiers can be found here.

In your case, you'd probably add the "earliest" and "latest" to your outer search, letting the time range picker drive the subsearch.

0 Karma

BP9906
Builder

I thought so too, but I tried that and get:

Invalid value "rt-5m" for time term 'earliest'

earliest="rt-5m"

sowings
Splunk Employee
Splunk Employee

The first warning indicates your earliest is ignored since the time range picker is using a real time window. The second warning is to tell you that the subsearch is running "over all time" because a smaller window wasn't applied.

Let's try changing the order of things--let's apply a narrower window to the subsearch, and then let the time range picker set the "last 5 minutes" part.

Add "earliest=rt-5m" to your subsearch, specifying "last 5 minutes, real time", then your outer search's time frame can be dictated by the time range picker.

0 Karma

BP9906
Builder

Thanks, I tried adding: earliest=-5m@s

index=weblog earliest=-5m@s [ search index=log AND "keyword" | fields + field_name ]

I get 2 warnings now:

-Search time modifiers are ignored in real-time searches

-[subsearch]: Subsearches of a real-time search run over all-time unless explicit time bounds are specified within the subsearch.

Am I doing something wrong?

0 Karma
Get Updates on the Splunk Community!

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

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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