Splunk Search

How to find the uncommon values of a field between two indexes?

amaurya1
Explorer

I have two indexes "abc" and "def". There is a field in index "abc" ---> "operator_id".
Similarly, there is a field in index "def" --> "worker_id".

My end goal is to find out those operator_ids which are present only in index "abc".
In my below search, I'm first finding out the common values between worker_id and operator_id. And I'm getting the right result,
but then I'm trying to find ids in index "abc" by eliminating the common values between the two columns but I'm getting all the values present in "abc".

index=abc  work_status=1 
operator_id =* NOT
[search index=abc  work_status=1 

[search index=def 
|stats count by  worker_id | rename worker_id as operator_id | table operator_id]

|stats count  by  operator_id]
|stats count  by  operator_id
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi amaurya1,
if you have few records in def index (less than 50,000) you could run something like this:

index=abc NOT [ search index=def | rename worker_id AS operator_id | fields operator_id ]
| ...

If instead you have more than 50,000 records in index def, you have to run something like this:

index=abc OR index=def
| eval operator_id=coalesce(operator_id,worker_id)
| stats values(index) AS index count BY operator_id
| search count=1 AND index=abc
| ...

Bye.
Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi amaurya1,
if you have few records in def index (less than 50,000) you could run something like this:

index=abc NOT [ search index=def | rename worker_id AS operator_id | fields operator_id ]
| ...

If instead you have more than 50,000 records in index def, you have to run something like this:

index=abc OR index=def
| eval operator_id=coalesce(operator_id,worker_id)
| stats values(index) AS index count BY operator_id
| search count=1 AND index=abc
| ...

Bye.
Giuseppe

amaurya1
Explorer

Thanks @gcusello .. This is working fine...

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