Splunk Search

If I want to use a field from the main search as a search criteria for a sub-search, what code should I write?

hasegawaarte
Explorer

If I want to use a field(alarm_time) from the main search as a search criteria for a sub-search, what code should I write?
In the following code, I want to search for the time they are working 

I want to search Conditions : work_start < alarm_time < work_end 
search results you want to get : (work_name=work_b)
____________________________________

| makeresults
|eval _raw="alarm_time,host,message
2022/03/26 18:05,test_node,test_down"
| multikv forceheader=1
| eval alarm_time_strp = strptime(alarm_time,"%Y/%m/%d %H:%M")
| join type=left host
[| makeresults
|eval _raw="host,work_start,work_end,work_name
test_node,2022/03/26 17:00,2022/03/26 18:00,work_a
test_node,22022/03/26 18:00,2022/03/26 19:00,work_b
test_node,2022/03/26 19:00,2022/03/26 20:00,work_c"
| multikv forceheader=1
| eval work_start_strp = strptime(work_start,"%Y/%m/%d %H:%M")
| eval work_end_strp = strptime(work_end,"%Y/%m/%d %H:%M")
]
Labels (1)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

In general case, you don't "pass parameters" to a subsearch. It's the other way around - the subsearch is evaluated first, its results are rendered to a condition or set of conditions which gets appended to the main search.

You can use the map command to launch a subsearch with parameters coming from the main search but it's for a very very rare cases.

As a rule of thumb you should avoid subsearches whenever you can - they have their limitations and can fail silently and fail you in a very nasty way.

Huge part of searches you'd initially try to write with subsearches (and joins) can be rewritten as stats.

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

In general case, you don't "pass parameters" to a subsearch. It's the other way around - the subsearch is evaluated first, its results are rendered to a condition or set of conditions which gets appended to the main search.

You can use the map command to launch a subsearch with parameters coming from the main search but it's for a very very rare cases.

As a rule of thumb you should avoid subsearches whenever you can - they have their limitations and can fail silently and fail you in a very nasty way.

Huge part of searches you'd initially try to write with subsearches (and joins) can be rewritten as stats.

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!

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...