# Categorize with keywords and assign value

**URL:** <https://discuss.elastic.co/t/categorize-with-keywords-and-assign-value/59121>\
**Category:** Logstash\
**Created:** [August 28, 2016, 3:45pm UTC](https://discuss.elastic.co/t/categorize-with-keywords-and-assign-value/59121 "2016-08-28T15:45:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [August 28, 2016, 3:45pm UTC](https://discuss.elastic.co/t/categorize-with-keywords-and-assign-value/59121/1 "2016-08-28T15:45:23Z")

</div>

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

![](https://us1.discourse-cdn.com/elastic/original/2X/8/8ecf9a3d8571fddb6b9d7c526dedeca5da493a82.png)

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

Please help out here

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 28, 2016, 7:19pm UTC](https://discuss.elastic.co/t/categorize-with-keywords-and-assign-value/59121/2 "2016-08-28T19:19:43Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [August 29, 2016, 5:55am UTC](https://discuss.elastic.co/t/categorize-with-keywords-and-assign-value/59121/3 "2016-08-29T05:55:37Z")

</div>

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"}} }

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 29, 2016, 6:18am UTC](https://discuss.elastic.co/t/categorize-with-keywords-and-assign-value/59121/4 "2016-08-29T06:18:42Z")

</div>

```
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.

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [August 29, 2016, 7:35am UTC](https://discuss.elastic.co/t/categorize-with-keywords-and-assign-value/59121/5 "2016-08-29T07:35:35Z")

</div>

Thanks , this has solved my problem

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:41am UTC](https://discuss.elastic.co/t/categorize-with-keywords-and-assign-value/59121/6 "2017-07-06T04:41:12Z")

</div>

Closed on July 6, 2017, 4:41am UTC


