Splunk Search

Use eval statement with and, if, then

mistydennis
Communicator

Example: I'm trying to count how many books we have in our database based on subject: children's, romance, travel, etc. Right now I have a chart that lists out the subject and the count. But I need to pull out a certain type of book and break it down into further categories based on additional metadata. What statement can I use for something like this:

if book=travel AND author=James, then localtravel. If not, foreigntravel.

I'm trying to get everything to fall into one column beneath "Book Type" so it reads:

Children
Romance
LocalTravel
ForeignTravel

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

Your Base Search Here
| eval book = case(
    (book="travel" AND author="James"), "localtravel",
        ...
    Other "localtravel" Cases Here
        ...
    (book="travel"),                    "foreigntravel",
        ...
    Other Cases Here
        ...
    true(),                             book)

View solution in original post

woodcock
Esteemed Legend

Like this:

Your Base Search Here
| eval book = case(
    (book="travel" AND author="James"), "localtravel",
        ...
    Other "localtravel" Cases Here
        ...
    (book="travel"),                    "foreigntravel",
        ...
    Other Cases Here
        ...
    true(),                             book)

mistydennis
Communicator

Thank you, that's exactly what I was looking for!

cmerriman
Super Champion

you can do a if statement:

|eval BookType=if(book="travel" AND author="James","LocalTravel","ForeignTravel")

if you need to add more to it, use a case statement.

if you can create a lookup table with all the fields you'd like to compare, that might be best, if there are a lot.

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...