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!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...