Categorize with keywords and assign value

Hi All

I have a Field called Description and using mutate i want add a new field called category
Description has certain words like cat, dog
If cat keyword comes then assign value Cat and with dog keyword with Category value as Dog
if no cat and dog keyword value then None

Like in below table

I have tried this filter with mutate and grok
But i am not able to define right if else condition

Please help out here

if "cat" in [Description] {
  mutate {
    add_field => {
      "Category" => "Cat"
    }
  }
} else if "dog" in [Description] {
  ...
} else {
  mutate {
    add_field => {
      "Category" => "None"
    }
  }
}

Thanks for your reply

What if i will have multiple string and want to categorize that as Cat

for example

Cat and Kitten are in couch : Cat
Kitten are in Sofa: Cat

I have tried this but not working

if ["cat", "kitten"] in [Description] {
{mutate {add_field => {"Category" => "Cat"}} }

if "cat" in [Description] or "kitten" in [Description]

Note that this is comparison is case-sensitive. You'll either have to switch to a case-insensitive regexp match or lowercase the contents of the field where you're looking for the pets.

1 Like

Thanks , this has solved my problem