Splunk Search

mvfind can't see spaces and parenthesis

LHAYNES020
Explorer

I'm trying to use where(isnotnull(mvfind(mvfield,field))) to search to see which records are part of a list. The fields are all strings, and some of them have parentheticals at the end. I noticed that mvfind does not seem to capture these fields. To illustrate my point, try the following search.

 

 

| makeresults count=10 
| streamstats count as n 
| eval n=n-1 
| eval n=case(n<3,"Test (".n.")",n<6,"Test ".n,n<9,"(".n.")",1=1,n) 
| eventstats list(n) as mv 
| eval index=mvfind(mv,n)

 

 

When you do, you'll see that items 3-9 are captured, but 0-2 are not, even though the very values of n were used to generate the mv field.

I currently have a workaround to just use rex commands to substitute different strings for the parenthesis, run my mvfind, and then use rex to substitute them back, but it feels a little ridiculous. Does anyone know why mvfind doesn't work here or a cleaner way to fix it? 

 

Labels (4)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The mvfind function matches by regular expression rather than exact string.  The parentheses in n represent a capture group and don't match the text in mv.  I cannot, however, explain why the code works for values 6-8.

 

| makeresults count=10 
| streamstats count as n 
| eval n=n-1 
| eval n=case(n<3,"Test (".n.")",n<6,"Test ".n,n<9,"(".n.")",1=1,n) 
| eventstats list(n) as mv 
| eval n=replace(n,"\(", "\\("), n=replace(n,"\)", "\\)")
| eval index=mvfind(mv,n)

 

 

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

ITWhisperer
SplunkTrust
SplunkTrust

This might give a better example of how mvfind works

| makeresults count=10 
| streamstats count as n 
| eval n=n-1 
| eval n=case(n<3,"Test (".n.")",n<6,"Test ".(n-3),n<9,"(".(n-6).")",1=1,n) 
| eventstats list(n) as mv 
| eval index=mvfind(mv,n)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

mvfind is working correctly, the second parameter is taken as a regex so you are right to substitute in escape characters where necessary.

https://docs.splunk.com/Documentation/SCS/current/SearchReference/MultivalueEvalFunctions#mvfind.28.... 

0 Karma
Get Updates on the Splunk Community!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

Stay Connected: Your Guide to October Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...