Splunk Search

Splunk - join two search queries having common field

Nidheesh
Explorer

Hi,

I need to join two splunk search queries based on a common field (JoinId).

All I would like to have at the output is to return how many values of that particular common field is mapped from both queries and how many are unmapped from query2.

Can someone help me with this?

query1:

index="source1" "layer-monitor" ServiceEvent "debug"| search NOT ErrorMessage=* | stats count(JoinId) as "Total success"

query2:

index="source2" sourcetype="sourceData" "Message=Log Message invoked" JoinId

I would like to know how many JoinId fields of query2 are unmapped with respect to query1 JoinId

0 Karma
1 Solution

cmerriman
Super Champion

maybe something like this:

(index="source1" "layer-monitor" ServiceEvent "debug" NOT ErrorMessage=*) OR (index="source2" sourcetype="sourceData" "Message=Log Message invoked" JoinId)|eval source1JoinId=if(index="source1",JoinId,null())|eval source2JoinId=if(index="source2",JoinId,null())|stats count(source1JoinId) as s1JoinId count(source2JoinId) as s2JoinId by JoinId|eval unmappedSource2=if(s2JoinId=0 AND s1JoinId>0,1,0)|stats sum(unmappedSource2) as unmappedSource2

that should give you how many JoinIds in source2 are not in source1. You can break the syntax apart pipe by pipe to double check it's working properly

View solution in original post

lfedak_splunk
Splunk Employee
Splunk Employee

Hey @Nidheesh, if either of these solutions work for you, please remember to "Accept" the answer. You can upvote posts as well. (Karma points will be awarded for either action.) Happy Splunking!

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi Nidheesh,
Try something like this

index="source2" sourcetype="sourceData" "Message=Log Message invoked"  NOT [ search index=source1 "layer-monitor" ServiceEvent debug NOT ErrorMessage=* | dedup JoinId | fields JoinId ]
| dedup JoinId
| table JoinId

Bye.
Giuseppe

0 Karma

cmerriman
Super Champion

maybe something like this:

(index="source1" "layer-monitor" ServiceEvent "debug" NOT ErrorMessage=*) OR (index="source2" sourcetype="sourceData" "Message=Log Message invoked" JoinId)|eval source1JoinId=if(index="source1",JoinId,null())|eval source2JoinId=if(index="source2",JoinId,null())|stats count(source1JoinId) as s1JoinId count(source2JoinId) as s2JoinId by JoinId|eval unmappedSource2=if(s2JoinId=0 AND s1JoinId>0,1,0)|stats sum(unmappedSource2) as unmappedSource2

that should give you how many JoinIds in source2 are not in source1. You can break the syntax apart pipe by pipe to double check it's working properly

Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

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