Splunk Dev

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

thanhphan
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

gcusello
SplunkTrust
SplunkTrust

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

Bye.
Giuseppe

0 Karma

renjith_nair
Legend

@thanhphan,

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!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...