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!

What the End of Support for Splunk Add-on Builder Means for You

Hello Splunk Community! We want to share an important update regarding the future of the Splunk Add-on Builder ...

Solve, Learn, Repeat: New Puzzle Channel Now Live

Welcome to the Splunk Puzzle PlaygroundIf you are anything like me, you love to solve problems, and what ...

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...