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.

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...