Splunk Search

data and lookup field problem

secure
Path Finder

Hi All

i have a csv look up with below data

Event_Code

AUB01

AUB36

BUA12

i want to match it with a dataset which has field name  Event_Code with several values i need to extract the count of the event code per day from the matching csv lookup 

my query

index=abc 
|rex field=data "\|(?<data>[^\.|]+)?\|(?<Event_Code>[^\|]+)?\|"
| lookup dataeventcode.csv Event_Code
| timechart span=1d dc(Event_Code)

however the result is showing all 100 count per day instaed of matching the event code from the CSV and then give the total count per day

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @secure ,

if you want to filter results from main search using the Event_Codes from the lookup, you must use a subsearch:

index=abc 
| rex field=data "\|(?<data>[^\.|]+)?\|(?<Event_Code>[^\|]+)?\|"
| search [ | inputlookup dataeventcode.csv | fields Event_Code ]
| timechart span=1d dc(Event_Code)

If you extract the Event_Code field before the search as a field, you can put the subsearch in the main search.

Ciao.

Giuseppe

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

The query checks the lookup file, but then does nothing with it.  That's why all events are counted.  Try this

index=abc 
|rex field=data "\|(?<data>[^\.|]+)?\|(?<Event_Code>[^\|]+)?\|"
| lookup dataeventcode.csv Event_Code OUTPUT Event_Code as found
| where isnotnull(found)
| timechart span=1d dc(Event_Code)

If the Event_Code field did not need to be extracted via rex then we could have used inputlookup to give Splunk a list of codes to search for.

---
If this reply helps you, Karma would be appreciated.

gcusello
SplunkTrust
SplunkTrust

Hi @secure ,

if you want to filter results from main search using the Event_Codes from the lookup, you must use a subsearch:

index=abc 
| rex field=data "\|(?<data>[^\.|]+)?\|(?<Event_Code>[^\|]+)?\|"
| search [ | inputlookup dataeventcode.csv | fields Event_Code ]
| timechart span=1d dc(Event_Code)

If you extract the Event_Code field before the search as a field, you can put the subsearch in the main search.

Ciao.

Giuseppe

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...