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
SplunkTrust
SplunkTrust

@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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...