Splunk Search

How to efficiently match events to lookup with wildcards across multiple fields (prefer most specific match)?

tomapatan
Contributor

I'm working with a CSV lookup  that contains multiple fields which may include wildcard (*) values.
The lookup is structured such that some rows are very specific and others are generic (e.g. *, *, *, HOST, *). I want to enrich events from my base search with the best matching Offset (name of the field) from the lookup.

Challenges:

  • Using lookup definition with match_type=WILDCARD(...) only works well if there’s a unique match — but in my case, I need to evaluate multiple potential matches and choose the most specific one.

  • Using | map works correctly, but it's too slow.

 

 

Labels (1)
0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi @tomapatan 

If you structure your lookups so that the more generic match is lower down the lookup than your more specific match, and you have your "Max Matches" set to 1 then it should match the more specific value first, else match the more generic one if not found.

For example - this is my test lookup:

livehybrid_0-1749111227530.png

You can see the more specific values are at the top.

I have configured a lookup definition with WILDCARD matches and a max matches = 1

livehybrid_1-1749111263666.png

Then I run a search, if country/town isnt set I am setting to "Unknown" but it could be any value.

livehybrid_2-1749111324844.png

 

It maps to 999 because this is the generic value for host1 if town/country is not set.

If I now set the country=UK:

livehybrid_3-1749111351660.png

 

I get a more specific value returned because it matches country=UK town=*

If I do host=host999 it matches host* in the lookup and I get an interestingField value of GHI:

livehybrid_4-1749111404543.png

 

Remember that you have to pass all the fields you want to match on to the lookup command, and you should have the more generic matches lower down the lookup file.

🌟 Did this answer help you? If so, please consider:

  • Adding karma to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...