Building for the Splunk Platform

How do I pass some subsearch result fields to the result?

New Member

I'm trying to figure out if the following can be done with subsearch or requires a join.
I'm running a search that boils down to:

index=indexA sourcetype=outer 
  [search index=indexB sourcetype=inner innerinput=abc | fields inneroutput1 inneroutput2 inneroutput3]
| table _time host outeroutput1 outeroutput2 **inneroutput3**

My subsearch results provide the keys necessary for the main one, but I'd like one extra field to be passed to the final table without being used on the outer search.

Anything I'm missing or do I have to run a join just for that extra field?

Tags (1)
0 Karma

Esteemed Legend

Hi thanhphan,
let me understand: do you want to list events both from main search and subsearch or do you want to filter events from main search with the results of subsearch?
using the search you described, you reach the second solution and to add fields of the subsearch you have to use the join command.
So if inneroutput1 inneroutput2 inneroutput3 are three fields used to match the searches:

index=indexA sourcetype=outer 
| join inneroutput1 inneroutput2 inneroutput3 [search index=indexB sourcetype=inner innerinput=abc ]
| table _time host outeroutput1 outeroutput2 inneroutput3

Join isn't a very performant command, so you could also use something like this:

(index=indexA sourcetype=outer) OR (index=indexB sourcetype=inner innerinput=abc)
| stats dc(index) AS num_ind earliest(_time) AS _time values(host) AS host BY outeroutput1 outeroutput2 inneroutput3
| where num_ind>1
| fields - num_ind


0 Karma



Try using return in the subsearch. ie . return inneroutput3

Please be aware that by default, subsearches return a maximum of 10,000 results and have a maximum runtime of 60 seconds.

Happy Splunking!
0 Karma
Get Updates on the Splunk Community!

Observability Highlights | January 2023 Newsletter

 January 2023New Product Releases Splunk Network Explorer for Infrastructure MonitoringSplunk unveils Network ...

Security Highlights | January 2023 Newsletter

January 2023 Splunk Security Essentials (SSE) 3.7.0 ReleaseThe free Splunk Security Essentials (SSE) 3.7.0 app ...

Platform Highlights | January 2023 Newsletter

 January 2023Peace on Earth and Peace of Mind With Business ResilienceAll organizations can start the new year ...