# How to add tags to the Document , based on the dictionary

**URL:** <https://discuss.elastic.co/t/how-to-add-tags-to-the-document-based-on-the-dictionary/162225>\
**Category:** Logstash\
**Created:** [December 27, 2018, 11:42am UTC](https://discuss.elastic.co/t/how-to-add-tags-to-the-document-based-on-the-dictionary/162225 "2018-12-27T11:42:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adityaPsl](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@adityaPsl](https://discuss.elastic.co/u/adityaPsl)\
**Post date:** [December 27, 2018, 11:42am UTC](https://discuss.elastic.co/t/how-to-add-tags-to-the-document-based-on-the-dictionary/162225/1 "2018-12-27T11:42:40Z")

</div>

Hello Team,

I am new to the ELK stack.  
I have a use case where I need to tag documents based on the dictionary. Where Dictionary key is String and value is list of Strings.  
So basically if the document field matches with dictionary key (regex pattern) then I want to add all the values as tags to that document.

For example.

Input  
Doc1 :  
{  
"Field 1" :"A",  
"Field 2":"B",  
"Field 3":"abcd"

}

Doc2:  
{  
"Field 1" :"C",  
"Field 2":"D",  
"Field 3":"abcd1"

}

Dictionary :  
{ "abcd1": \<"abcd1","abcd11","abcd111"\>,  
"abcd2":\<abcd2","abcd22","abcd222"\>  
}

Here Doc1 matches with both the Dictionary entries so Doc1 should be tagged with all the values ("abcd1","abcd11","abcd111","abcd2","abcd22","abcd222")

But Doc2 matches with only 1st Dictionary entry  
So it should be tagged with only entry 1 values (  
"abcd1","abcd11","abcd111")

Any pointers would be really helpful.

Thanks in advance.  
Aditya

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [December 27, 2018, 4:43pm UTC](https://discuss.elastic.co/t/how-to-add-tags-to-the-document-based-on-the-dictionary/162225/2 "2018-12-27T16:43:58Z")

</div>

You can use

```
if "value" in "list" {
   # do stuff
}

```

I think this should work in your use case... It just a bunch of if else..

---

<div class="post-metadata">

**Author:** ![adityaPsl](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@adityaPsl](https://discuss.elastic.co/u/adityaPsl)\
**Post date:** [December 27, 2018, 6:08pm UTC](https://discuss.elastic.co/t/how-to-add-tags-to-the-document-based-on-the-dictionary/162225/3 "2018-12-27T18:08:24Z")

</div>

Hello pjanzen,

Thanks for your reply.

Is there any way we can add a loop and keep dictionary terms in a config file,  
writing if else may not work as dictionary terms may get changed over the period of time. like new terms would get added or some terms may get deleted.

Thank you,  
Aditya

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [December 27, 2018, 6:32pm UTC](https://discuss.elastic.co/t/how-to-add-tags-to-the-document-based-on-the-dictionary/162225/4 "2018-12-27T18:32:34Z")

</div>

No, you cannot keep dictionaries in a seperate file. You could do something with the elasticsearch filter plugin and store your dict data there.

---

<div class="post-metadata">

**Author:** ![adityaPsl](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@adityaPsl](https://discuss.elastic.co/u/adityaPsl)\
**Post date:** [December 28, 2018, 6:37am UTC](https://discuss.elastic.co/t/how-to-add-tags-to-the-document-based-on-the-dictionary/162225/5 "2018-12-28T06:37:40Z")

</div>

Ok, Thank you pjanzen.  
Just wanted to check can we use Translate filter plugin.

Thank you,  
Aditya

---

<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:** [January 25, 2019, 6:37am UTC](https://discuss.elastic.co/t/how-to-add-tags-to-the-document-based-on-the-dictionary/162225/6 "2019-01-25T06:37:50Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
