Splunk Search

Help me with join query

sravankaripe
Communicator

index=ABC sourcetype=xyz | stats count by XID| table XID count

XID Count
101 2
102 3
103 4

index=ABC sourcetype=pqr | table MyID Name

MyID Name
101 jhgkjmhgku
102 jhkfythhgkk
103 kiugikyukhy

How to join this to get result.

MyID Name count
101 jhgkjmhgku 2
102 jhkfythhgkk 3
103 kiugikyukhy 4

0 Karma
1 Solution

SplunkersRock
Path Finder

try this

index=ABC sourcetype=xyz | stats count by XID | appendcols [search index=ABC sourcetype=pqr | table MyID Name] | table MyID Name count

View solution in original post

0 Karma

jacobwilkins
Communicator

I always try to avoid commands that use subsearches since they don't scale.

You should be able to get the job done with this:

index=ABC (sourcetype=xyz OR sourcetype=pqr)
 | eval joinid=coalesce(XID,MyID)
 | stats count(XID) AS Count, values(Name) AS Name by joinid
 | rename joinid AS MyID

This takes some extra steps for clarity, but the gist is that you are using the "by" field in the stats to perform the "join". The count will be constrained to only events with an XID field, meaning that your sourcetype=pqr events won't influence your count, even though they are in the resultset.

0 Karma

SplunkersRock
Path Finder

try this

index=ABC sourcetype=xyz | stats count by XID | appendcols [search index=ABC sourcetype=pqr | table MyID Name] | table MyID Name count

0 Karma

ckunath
Communicator
index=ABC sourcetype=xyz | stats count by XID | rename XID as MyID
| join MyID [index=ABC sourcetype=pqr | table MyID Name]
| table MyID Name count

DalJeanis
SplunkTrust
SplunkTrust

Yup. Or,

 index=ABC sourcetype=xyz OR sourcetype=pqr 
| eval MyID = coalesce(MyID,XID)
| stats count(eval(sourcetype=xyz)) as count, values(Name) as Name by MyID 
0 Karma
Get Updates on the Splunk Community!

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

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...