Splunk Search

compare fields for like match

rg33
Explorer

I am looking for methods to compare two fields for a like match.

Specifically, I'd like to match when field1 can be found within field2. Also, I would like the comparison to be support either case sensitive or insensitive options. Fuzzy matching, including degree of similarity or confidence values, would also be helpful.

For example, given two events:

event1  field1="race"  field2="Racecar"
event2  field1="jump"  field2="Rope"
event3  field1="flip"  field2="BackFlip"

Desired result:

  event1  result=hit
  event2  result=miss
  event3  result=hit

Thanks in advance for your suggestions.

-rg

1 Solution

rg33
Explorer

One solution:

Case sensitive matching:

search ... | eval results = if(match(field2,field1), "hit", "miss") 

Case insensitive matching:

search ... | eval results = if(match(upper(field2),upper(field1)), "hit", "miss") 

I hope this helps others. I tried quite a few other ways before discovering this.

View solution in original post

rg33
Explorer

One solution:

Case sensitive matching:

search ... | eval results = if(match(field2,field1), "hit", "miss") 

Case insensitive matching:

search ... | eval results = if(match(upper(field2),upper(field1)), "hit", "miss") 

I hope this helps others. I tried quite a few other ways before discovering this.

mad4wknds
Path Finder

I downvoted this post because error in 'eval' command: the arguments to the 'if' function are invalid.

0 Karma

rg33
Explorer

I fixed the error. Sorry for the typo.

0 Karma

xploresplunk
New Member

How would you get the time for which these two fields matched each other? Further, if it matches several times how would you get the first time they matched (earliest time)?

0 Karma

countermancs
New Member

I am trying to match a the values of a 1 field with the values of another field .

When i use this eval I get Error in 'eval' command: The arguments to the 'match' function are invalid.

any ideas?

0 Karma

dfqobvbkmnpi
Explorer

looks like you have an extra ) or not enough ( in the case sensitive solution.

0 Karma

dwaddle
SplunkTrust
SplunkTrust

Is this both question and answer? If so, you should edit it so the answer appears in an answer response below. That is more clear and you can get karma for a correct answer to your question and a "self-learner" badge for answering your own question 🙂

0 Karma
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!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...