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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...