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

Meet Splunk Observability Studio: AI-Assisted OpenTelemetry Instrumentation Without ...

Instrumentation is usually the last step or even an afterthought when building out a project. The feature ...

Federated Search for Cisco Security and Analytics Logging (SAL) is now GA on Splunk ...

Federated Search for Cisco  Security Analytics and Logging (SAL) is now generally available as part of the ...

Your Path to AgenticOps: AI Experiences for Every Splunk Practitioner

Your Path to AgenticOps: AI Experiences for Every Splunk Practitioner   Join us for a demo-driven look at how ...