Splunk Search

conditional lookup with catch-all value

thezen
Explorer

I am looking to retrieve the following a field from a lookup table depending on the lookup result of two fields as follow,

Current lookup table sample:

FIELD1  FIELD2  MATCHTAG    UNMATCHEDTAG
A       123     string1 string2
B       456     string3 string4

All of the events will always have a matching value for field1, but not on field2. Those event which has a matching for both field1 and field2 will have to append the corresponding MATCHTAG field value (string1), otherwise (if it doesn't have matching value for FIELD2) it will have to append "string2" instead to the result set (which will also contain the matching events).

Event Sample,

A 123 
A 789
B 789

Ideal Result,

A 123 string1
A 789 string2
B 789 string4

I know we can do a lookup and return the non-matching result set, but not so sure on how I can append the UNMATCHEDTAG to the result set together.

Appreciate any suggestions on this,

Tags (1)
0 Karma
1 Solution

thezen
Explorer

Managed to do it by using enabling wildcard on the field and then use mvindex to do catch-all.

View solution in original post

0 Karma

Vijeta
Influencer

You can try this , I don't know the field names so you will have t change in query accordingly

index=<yourindex> |join fields1[|inputlookup <yourlookup>.csv |rename FIELD2 as lookup_field2| fields Flookup_field2 MATCHED UNMATCHED]| eval string=if(field2= lookup_field2, MATCHED,UNMATCHED)| fields field1 field2 string
0 Karma

thezen
Explorer

Managed to do it by using enabling wildcard on the field and then use mvindex to do catch-all.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

@thezen, If your problem is resolved, please accept an answer to help future readers.

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

harsmarvania57
Ultra Champion

Hi @thezen,

Try below query

<yourBaseSearch>
| lookup yourlookup.csv raw_field1 AS FIELD1, raw_field2 AS FIELD2 OUTPUT MATCHTAG AS MATCHTAG, UNMATCHEDTAG AS UNMATCHEDTAG 
| eval merged_tag = coalesce(MATCHTAG, UNMATCHEDTAG)
0 Karma

thezen
Explorer

thanks but it doesn't seem to work in my case, I need all of the original events including the one which is not mached to be part of the result.

0 Karma
Get Updates on the Splunk Community!

What's New in Splunk Cloud Platform 9.3.2411?

Hey Splunky People! We are excited to share the latest updates in Splunk Cloud Platform 9.3.2411. This release ...

Buttercup Games: Further Dashboarding Techniques (Part 6)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...