Splunk Search

Disjoint results of multiple searches

mhagoel
Engager

I have 2 query searches, one returns set result A and the other one returns set result B. 

I would like to get the results of A/B (results that appear in A but do not appear in B )

To be more specific:

First query is:

index="<...>" "attrs.pod"="<...> "attrs.env"=<...> "some log message" "accountId=1234" | rex field=line "accountId=(?<account_id>[0-9]+).*correlationId=(?<correlation_id>[\w-]+)" | stats values(correlation_id)

 

 

The  query returns a list of correlation_id, such as:

values(correlation_id)

11
22
33

 

Second query is almost identical (different log message) :

index="<...>" "attrs.pod"="<...> "attrs.env"=<...> "Other log message" "accountId=1234" | rex field=line "accountId=(?<account_id>[0-9]+).*correlationId=(?<correlation_id>[\w-]+)" | stats values(correlation_id)

 

 

 

So the result is in the same structure,  for example 

values(correlation_id)

11
88

 

 

I would like a query which results in A/B, so in this case it should be 

values(correlation_id)

22
33

 

I tried this query but it doesn't work:

index="<...>" "attrs.pod"="<...> "attrs.env"=<...> "some log message" "accountId=1234" | rex field=line "accountId=(?<account_id>[0-9]+).*correlationId=(?<correlation_id>[\w-]+)" | stats values(correlation_id)

| search NOT in

[search index="<...>" "attrs.pod"="<...> "attrs.env"=<...> "Other log message" "accountId=1234" | rex field=line "accountId=(?<account_id>[0-9]+).*correlationId=(?<correlation_id>[\w-]+)" | stats values(correlation_id)]

 

 

 

Labels (3)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@mhagoel 

Can you please try this?

YOUR_FIRST_SEARCH | stats values(correlation_id) as correlation_id_A | appendcols [YOUR_SECOND_SEARCH| stats values(correlation_id) as correlation_id_B] | mvexpand correlation_id_A 
| eval flg=mvfind(correlation_id_B,correlation_id_A) | where isnull(flg) | table correlation_id_A

 

My Sample Search :

| makeresults | eval _raw="correlation_id
11
22
33"|multikv forceheader=1 | stats values(correlation_id) as correlation_id_A | appendcols [| makeresults | eval _raw="correlation_id
11
88"|multikv forceheader=1 | stats values(correlation_id) as correlation_id_B] | mvexpand correlation_id_A 
| eval flg=mvfind(correlation_id_B,correlation_id_A) | where isnull(flg) | table correlation_id_A


 Thanks
KV
▄︻̷̿┻̿═━一   ?

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@mhagoel 

Can you please try this?

YOUR_FIRST_SEARCH | stats values(correlation_id) as correlation_id_A | appendcols [YOUR_SECOND_SEARCH| stats values(correlation_id) as correlation_id_B] | mvexpand correlation_id_A 
| eval flg=mvfind(correlation_id_B,correlation_id_A) | where isnull(flg) | table correlation_id_A

 

My Sample Search :

| makeresults | eval _raw="correlation_id
11
22
33"|multikv forceheader=1 | stats values(correlation_id) as correlation_id_A | appendcols [| makeresults | eval _raw="correlation_id
11
88"|multikv forceheader=1 | stats values(correlation_id) as correlation_id_B] | mvexpand correlation_id_A 
| eval flg=mvfind(correlation_id_B,correlation_id_A) | where isnull(flg) | table correlation_id_A


 Thanks
KV
▄︻̷̿┻̿═━一   ?

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

Get Updates on the Splunk Community!

Building Reliable Asset and Identity Frameworks in Splunk ES

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

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...