Splunk Search

How to use subsearches on a different index?

chicocinco
Observer

I want to search all the email logs for a mail transaction.  However we have multiple indexes for our mail logs. 

When i run the search below , it gets the qid  which is the expected behavior. 

 

sourcetype=INDEX_B index=INDEX_B
[search sourcetype=INDEX_A to=*<email address>* | fields msgid |rename msgid as hdr_mid] | table qid

 

where: 

 

msgid/hdr_mid = unique email id in index_A. I have to rename msgid to hdr_mid as thats the name of the field in INDEX_A
qid = another unique id in INDEX_B  that corresponds to INDEX_A

 

What i want to accomplish is that the result of the qid will immediately search all match in INDEX_B but its not generating any search result. Below is the  modified version i made.

 

sourcetype=INDEX_B index=INDEX_B
[search sourcetype=INDEX_B index=INDEX_B | search
[search sourcetype=INDEX_A to=*<email address>* | fields msgid |rename msgid as hdr_mid | rename qid as search]] | table qid

 

 

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Will something like this work?

sourcetype=INDEX_B index=INDEX_B
[search sourcetype=INDEX_B index=INDEX_B
[search sourcetype=INDEX_A to=*<email address>* | fields msgid |rename msgid as hdr_mid] | table qid]
0 Karma

chicocinco
Observer

i tried your suggestions that is remove the second search and move one of the bracked to the last and it threw an error instead

0 Karma

yuanliu
SplunkTrust
SplunkTrust

You get an error because you didn't substitute "<email address>" with a literal string as you originally intended. (You should get the same error if you run your original search with the angled brackets.)

Meanwhile, the original question is rather ambiguous.  If the qid values from the table command are the matching qid from the subsearch, the results from 

sourcetype=INDEX_B index=INDEX_B
[search sourcetype=INDEX_A to=*<email address>* | fields msgid |rename msgid as hdr_mid]]

already contain everything matching these qid's.  What else is expected? (I take that the statement  "I have to rename msgid to hdr_mid as thats the name of the field in INDEX_A" should read as "I have to rename msgid to hdr_mid as thats the name of a matching field in INDEX_B.")

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...