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

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...