Splunk Search

How to use a sub-search result value as a search query in the main search

leykmekoo
Explorer

Hello, 

I've been attempting to use the results of a sub-search as input for the main search with no luck. I'm getting no results. Based on the query below, I was thinking of getting the field value of Email_Address  from the sub-search and passing the result to the main search (in my mind only the Email_Address value). Finally, thinking the main search now has the resulting values from the sub-search (the Email_Address field), it then runs the main search using the passed value (Email_Address) as a search criteria to find events from another index. Is that the correct way to pass values as a searchable value or am I wrong? If I'm wrong, how can I do this? I thank you all in advance for your assistance! 

index=firstindex Email_Address

[search index=secondindex user="dreamer"

     | fields Email_Address

     | head 1 ]

|table Date field1 field2 Email_Address

Labels (1)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

In your outer search 

index=firstindex Email_Address

remove the word "Email_Address" - I assume you want to look for a field that is called Email_Address in the firstIndex data using the values coming from the subsearch, but with this search you are looking for the WORD Email_Address as well as the value of the Email_Address FIELD  coming from the subsearch.

You can see what a subsearch returns by running it on its own and using the | format specifier, e.g.

index=secondindex user="dreamer"
| fields Email_Address
| head 1 
| format

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @leykmekoo,

are you sure that the field to use as search key is exactly named "Email_Address" in both the searches and that values are compatible?

if you manually extract a value from the subsearch, do you have results using this result in the main search?

Ciao.

Giuseppe

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