Splunk Search

How to connect two different indexes by unique item code showing count / percent (with match) & (without match)?

timothytruax
Explorer
  • I have 2 indexes.
  • 1st index (Index1) has a unique item code (Item1) for an item when it enters a process.
  • 2nd index (Index2) should have the same unique item code (Item2) when the item exits the process.
  • I want to produce report showing a count / percent where the (Index1.Item1 = Index2.Item2) & where (Index1.Item1 <> Index2.Item2).

Please show examples of SPL if possible and thank you!

0 Karma

somesoni2
Revered Legend

Try something like this

(index=index1 other parts ) OR (index=index2 other parts)
| eval itemCode=coalesce(item1,item2)
| stats dc(index) as reportedBy by itemCode
| stats count as Count by reportedBy | eventstats sum(Count) as Total
| eval Percent=round(Count*100/Total,2)
| eval ItemType=if(reportedBy=2,"Common in Both Indexes","Unique in Both Indexes")
| table ItemType Count Percent
0 Karma

deepashri_123
Motivator

Hey@timothytruax,

Try something like this,
if item1 and item2 has same fields then
index=index1 OR index=index2 | rename item2 as item1 | stats count dc(index) AS dc by item1 | where dc>1 | stats count .
This will give you the count of items having common values.

Let me know if this helps!!

0 Karma

timothytruax
Explorer

Hey deepashri_123 -
What if there is possibility of duplicates in Index1 of the Item1 and possibility of duplicates in Index2 of Item2?
I want to be sure that Index1.Item1 is actually present in Index2.Item2.

0 Karma

deepashri_123
Motivator

This query should give you exact count of items having values in both indexes.
Even if there is duplication. Just to confirm you need count of items common or event count?
Event count will need some other approach.

0 Karma

timothytruax
Explorer

Hey deepashri_123 -
I tried entering this one below; naturally with my fields and it did not work - it just shows a count = 0.

index=index1 OR index=index2 | rename item2 as item1 | stats count dc(index) AS dc by item1 | where dc>1 | stats count .

Any other suggestions? I continue to try different approaches.

0 Karma
Get Updates on the Splunk Community!

Database Performance Sidebar Panel Now on APM Database Query Performance & Service ...

We’ve streamlined the troubleshooting experience for database-related service issues by adding a database ...

IM Landing Page Filter - Now Available

We’ve added the capability for you to filter across the summary details on the main Infrastructure Monitoring ...

Dynamic Links from Alerts to IM Navigators - New in Observability Cloud

Splunk continues to improve the troubleshooting experience in Observability Cloud with this latest enhancement ...