Splunk Search

How to use eval for basic search terms (NOT fields)?

link22
Explorer

So I want to get the stats count of two search terms in a search that looks like this:
index=myIndex "searchTermA" OR "searchTermB" (these searches being strings to find certain applications under the index and they have no fields to search for them by nor are they similar enough for field extraction to work [individually field extracting these also proves to have a lot of issues as well]).

and what I wish I could do is this:

index=myIndex "searchTermA" OR "searchTermB"  | stats (or chart/timechart) count("searchTermA") count("searchTermB")

to get the data I want.

However, I am aware this is not possible. Is there some way to use eval to give these search strings a name and use them for count?

I also cannot go into the .conf files and edit them.

Thanks!

0 Karma
1 Solution

somesoni2
Revered Legend

You can something like this

index=myIndex "searchTermA" OR "searchTermB" | stats  count(eval(searchmatch("searchTermA"))) as CountA count(eval(searchmatch("searchTermB"))) as CountB

View solution in original post

0 Karma

somesoni2
Revered Legend

You can something like this

index=myIndex "searchTermA" OR "searchTermB" | stats  count(eval(searchmatch("searchTermA"))) as CountA count(eval(searchmatch("searchTermB"))) as CountB
0 Karma

brendanmatthews
Explorer

You can run something like ... |eval count_field = case(searchmatch("searchtermA"), "A_class",searchmatch("searchtermB"),"B_class") | stats (or chart/timechart) count by count_field. It should return the counts of both types of events.

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...