Splunk Search

compare data list

mkrauss1
Explorer

Assume i have two stores which must have the same items but one is missing.

My search returns for example

STORE=LONDON ITEM=ORANGE
STORE=LONDON ITEM=APPLE
STORE=PARIS ITEM=ORANGE
STORE=PARIS ITEM=APPLE
STORE=PARIS ITEM=LEMON

How can i display the missing item LEMON visible in store london?

Tags (1)
0 Karma
1 Solution

niketn
Legend

@mkrauss1, please find the following run anywhere search. It mimic three ITEMs and three STORES. You can expand to as many as you want. Obviously the query will be less expensive if there were lookups for unique STORES and ITEMS.

|  makeresults
|  eval data= "STORE=LONDON ITEM=BANANA;STORE=DELHI ITEM=ORANGE;STORE=LONDON ITEM=APPLE;STORE=PARIS ITEM=ORANGE;STORE=PARIS ITEM=APPLE;STORE=PARIS ITEM=LEMON"
|  makemv data delim=";"
|  mvexpand data
|  rename data as _raw
|  KV
|  table ITEM STORE
|  eventstats values(STORE) as AllStores
|  stats count as Match dc(AllStores) as MaxMatch values(STORE) as StoreFound values(AllStores) as AllStores by ITEM
|  search Match<MaxMatch
|  mvexpand AllStores
|  where !(AllStores in (StoreFound))
|  rename AllStores as StoreMissing
|  stats values(StoreFound) as StoreFound  values(StoreMissing) as StoreMissing by ITEM

PS: Commands till | table ITEM STORE create sample data for demo.
Also in command will work on Splunk Enterprise 6.6 onward.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

woodcock
Esteemed Legend

Like this:

| makeresults 
| eval raw="STORE=LONDON ITEM=ORANGE:STORE=LONDON ITEM=APPLE:STORE=PARIS ITEM=ORANGE:STORE=PARIS ITEM=APPLE:STORE=PARIS ITEM=LEMON" 
| makemv delim=":" raw 
| mvexpand raw 
| rename raw AS _raw 
| kv
| stats dc(STORE) AS num_stores values(STORE) AS stores BY ITEM
| search num_stores=1
0 Karma

niketn
Legend

@mkrauss1, please find the following run anywhere search. It mimic three ITEMs and three STORES. You can expand to as many as you want. Obviously the query will be less expensive if there were lookups for unique STORES and ITEMS.

|  makeresults
|  eval data= "STORE=LONDON ITEM=BANANA;STORE=DELHI ITEM=ORANGE;STORE=LONDON ITEM=APPLE;STORE=PARIS ITEM=ORANGE;STORE=PARIS ITEM=APPLE;STORE=PARIS ITEM=LEMON"
|  makemv data delim=";"
|  mvexpand data
|  rename data as _raw
|  KV
|  table ITEM STORE
|  eventstats values(STORE) as AllStores
|  stats count as Match dc(AllStores) as MaxMatch values(STORE) as StoreFound values(AllStores) as AllStores by ITEM
|  search Match<MaxMatch
|  mvexpand AllStores
|  where !(AllStores in (StoreFound))
|  rename AllStores as StoreMissing
|  stats values(StoreFound) as StoreFound  values(StoreMissing) as StoreMissing by ITEM

PS: Commands till | table ITEM STORE create sample data for demo.
Also in command will work on Splunk Enterprise 6.6 onward.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

MonkeyK
Builder

Great solution and I also really like the first part of the query to build a set of data. Both of these should be on some list of solution patterns.

niketn
Legend

Thanks @MonkeyK 🙂 I learnt KV and extract for mocking up data from @cmerriman 🙂
Most of community members devise these tricks to mock sample data as per question to assist users. Obviously we do not have access to user's data another reason is re-usability by other members and also testing.

You are right that such data generation queries can go to Tips & Tricks section of Splunk Blogs but not sure who can do that 🙂

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

niketn
Legend

@mkrauss1, will you always have two stores or can it be more than two as well?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

mkrauss1
Explorer

But a search for two stores would be great as well

0 Karma

mkrauss1
Explorer

can have many stores

0 Karma

niketn
Legend

Do you have lookup file for STORES or can you have a lookup file?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...