Splunk Search

How to combine index queries from different field names?

cclva
Explorer

I have two indexes:

IndexA has a `thisId` field.

IndexB has fields `otherId` and `name`.

I want to write a query which returns a table of all `thisIds` with a matching `name`. The challenge has been writing the query such that it doesn't return all the `otherId` fields as well.

My current query is:

(index="indexA") OR (index="indexB") | eval id=coalesce(thisId, otherId) | stats values(name) as name by id

However, this is returning all the ids in indexB as well.

Thank you

Labels (1)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

Yep, there is a problem with the editor. Luckily it's about to be resolved soon.

So you want only the values of 'name' from IndexB, for which there is an entry in IndexA with the corresponding id field?

You were relatively close

index=IndexA OR index=IndexB
| eval commonId=coalesce(thisId,otherId)
| stats dc(index) as count values(name) by commonId
| where count=2
| fields - count

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

Sorry, I fail to understand. If IndexA has 'thisId', how does it "match" the 'name' from IndexB?

0 Karma

cclva
Explorer

The values of `thisId` match `otherId`. `thisId` is a subset of `otherId`

Sorry, I've been trying to include an example, but the forum won't let me post the html.

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Yep, there is a problem with the editor. Luckily it's about to be resolved soon.

So you want only the values of 'name' from IndexB, for which there is an entry in IndexA with the corresponding id field?

You were relatively close

index=IndexA OR index=IndexB
| eval commonId=coalesce(thisId,otherId)
| stats dc(index) as count values(name) by commonId
| where count=2
| fields - count
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...