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!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...