Splunk Search

How to achieve vlookup in Splunk

karthikklv
Engager

Hi,

Kindly help me with the search query for my scenario.
I have a lookup table A and a search B with common field user_id. I need to find list of users who are present in lookup A, but not in Search B, over a period of time.

I did write query but it doesn't return any result.

|inputlookup A.csv | fields user_id | search user_id NOT [ search index=X sourcetype=P | fields USER_ID | dedup USER_ID | table USER_ID]

Appreciate your help. Thx.

Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi karthikklv,
try something like this

|inputlookup A.csv 
| eval count=0 
| append [ search index=X sourcetype=P | stats count by USER_ID]
| stats sum(count) AS Total by USER_ID
| where Total=0

Users with Total=0 are the ones present in lookup A and not present in search B.

if you're not sure about USER_ID case, you could put an eval to uppercase:

|inputlookup A.csv 
| eval count=0,  USER_ID=upper(USER_ID)
| append [ search index=X sourcetype=P | eval USER_ID=upper(USER_ID) | stats count by USER_ID]
| stats sum(count) AS Total by USER_ID
| where Total=0

Bye.
Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi karthikklv,
try something like this

|inputlookup A.csv 
| eval count=0 
| append [ search index=X sourcetype=P | stats count by USER_ID]
| stats sum(count) AS Total by USER_ID
| where Total=0

Users with Total=0 are the ones present in lookup A and not present in search B.

if you're not sure about USER_ID case, you could put an eval to uppercase:

|inputlookup A.csv 
| eval count=0,  USER_ID=upper(USER_ID)
| append [ search index=X sourcetype=P | eval USER_ID=upper(USER_ID) | stats count by USER_ID]
| stats sum(count) AS Total by USER_ID
| where Total=0

Bye.
Giuseppe

karthikklv
Engager

Thanks for the query. This is what I was exactly looking for.

0 Karma

hhGA
Communicator

Hi,

Can you give this a try:

| inputlookup A.csv
| table USER_ID
| join type=left USER_ID
[ search index=X sourcetype=P
| dedup USER_ID
| eval in_search="Yes"
| table USER_ID , in_search]
| WHERE in_search!="Yes"
| table USER_ID

0 Karma

karthikklv
Engager

Thank for the query. But, this didn't work for my scenario.

0 Karma
Get Updates on the Splunk Community!

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Shape the Future of Splunk: Join the Product Research Lab!

Join the Splunk Product Research Lab and connect with us in the Slack channel #product-research-lab to get ...