Splunk Search

How to pass a value from the outer search to the inner subsearch?

greg
Communicator

I'm trying to compose a search like this:

sourcetype=A | eval param=ceil(SomeField) | join Name [search sourcetype=B status<param | sort status | head 1] | table _time, Name, status

but it returns no results.

I guess it's because "param" is not visible (empty) in scope of inner search.
In other words, I want to parametrize the inner search so it could do some filtering over sourcetype B and return a single event to join to main search results.

Is there any way to pass the param value from the outer search to the inner subsearch?
Any help is greatly appreciated.

0 Karma
1 Solution

Ayn
Legend

No, the flow is the other way around, with data being available from the subsearch to the outer search.

Subsearches work much like backticks in *NIX environments in that they run first of all and then return their results before the rest of the query is run. I can't tell for sure what you're trying to achieve just by looking at the query, but perhaps you can switch places of the outer search and the subsearch?

View solution in original post

0 Karma

Ayn
Legend

No, the flow is the other way around, with data being available from the subsearch to the outer search.

Subsearches work much like backticks in *NIX environments in that they run first of all and then return their results before the rest of the query is run. I can't tell for sure what you're trying to achieve just by looking at the query, but perhaps you can switch places of the outer search and the subsearch?

0 Karma

greg
Communicator

Thanks for clarification, I'll try to rewrite the search in some other way. Switching places is not the case here.

The problem is the subsearch returns multiple results and join takes only one from the returned set (that looks strange and not like in SQL). I was able to combine the subsearch results into a single event using transaction and get them joined anyway, but then the rest of the search becomes complicated with all these splitting back makemv/mvexpand operators.

It would be much easier to make filtering in the subsearch.

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 at Splunk .conf24 ...

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