Dashboards & Visualizations

Searchmatch

suvi6789
Path Finder

Hi, 
I have doing a list of different searches and want the count of each searches. 
So, I was using the searchmatch command but when using it I get only the first result that is successfully searches and it ignore the rest

For example:

index="abc" 
| eval JobName= case(
searchmatch("error 1234", Error1),
searchmatch("error 567", Error2),
searchmatch("error 89", Error3)
)
| stats count by JobName

Output says 
Error1 - 234 (234 is the count of error)

though error 2 and error 3 are there, It is not listing in the results. 
Please could you suggest on how to get this sorted

 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

That's how case works - it returns the value for the first matching condition. If you want to evaluate all conditions, you have to do three separate evals and assign values to three separate fields.

0 Karma

suvi6789
Path Finder

Thank you for your response

If I comment the first search
index="abc" 
| eval JobName= case(
```searchmatch("error 1234"), "Error1",```
searchmatch("error 567"), "Error2",
searchmatch("error 89"), "Error3"
)

Now, the result is 
Error2 - 125

0 Karma

suvi6789
Path Finder

If I comment 
index="abc" 
| eval JobName= case(
```searchmatch("error 1234"), "Error1",```
searchmatch("error 567"), "Error2",
searchmatch("error 89"), "Error3"
)

Now, the result is 
Error2 - 125

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @suvi6789 ,

Only for test, please try this:

index="abc" 
| stats 
     count(eval(searchmatch("error 1234"))) AS "Error1"
     count(eval(searchmatch("error 567"))) AS "Error12"
     count(eval(searchmatch("error 89"))) AS "Error3"

the issue is probably on the data, you must analyze them

Ciao.

Giuseppe

0 Karma

suvi6789
Path Finder

Thanks for the response
My Bad, the parenthesis are wrong. I have ran the query with the right paranthesis. It was a typo.

index="abc" 
| eval JobName= case(
searchmatch("error 1234"), "Error1",
searchmatch("error 567"), "Error2",
searchmatch("error 89"), "Error3"
)
| stats count by JobName

Output says 
Error1 - 234 (234 is the count of error)

though error 2 and error 3 are there, It is not listing in the results. 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @suvi6789 ,

the search is correct, are you sure about the strings to search for Error 2 and 3?

Only for debugging, please change the order of searchmatch in the eval.

Ciao.

Giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @suvi6789 ,

parenthesis are wrong and if Error1,2 and3 are strings, use quotes:

index="abc" 
| eval JobName= case(
searchmatch("error 1234"), "Error1",
searchmatch("error 567"), "Error2",
searchmatch("error 89"), "Error3"
)
| stats count by JobName
0 Karma
Get Updates on the Splunk Community!

AI for AppInspect

We’re excited to announce two new updates to AppInspect designed to save you time and make the app approval ...

App Platform's 2025 Year in Review: A Year of Innovation, Growth, and Community

As we step into 2026, it’s the perfect moment to reflect on what an extraordinary year 2025 was for the Splunk ...

Operationalizing Entity Risk Score with Enterprise Security 8.3+

Overview Enterprise Security 8.3 introduces a powerful new feature called “Entity Risk Scoring” (ERS) for ...