# Please help, I cannot add two tags without replacing the tag that added first

**URL:** <https://discuss.elastic.co/t/please-help-i-cannot-add-two-tags-without-replacing-the-tag-that-added-first/160911>\
**Category:** Logstash\
**Created:** [December 14, 2018, 1:29pm UTC](https://discuss.elastic.co/t/please-help-i-cannot-add-two-tags-without-replacing-the-tag-that-added-first/160911 "2018-12-14T13:29:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harshet\_Jain](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@Harshet\_Jain](https://discuss.elastic.co/u/Harshet_Jain)\
**Post date:** [December 14, 2018, 1:29pm UTC](https://discuss.elastic.co/t/please-help-i-cannot-add-two-tags-without-replacing-the-tag-that-added-first/160911/1 "2018-12-14T13:29:16Z")

</div>

I have tried the following code but it does not work.

```
  event.set("[tags]", event.get("[tags]").push("PSY")) if event.get("[NAME]") != "ALPHA"
  event.set("[tags]", event.get("[tags]").push("OUR")) if event.get("[NAME]") == "DTD"

```

If I use the + sign - it appends the new tag with the old tag to make it -- "DeltaPSY"

how should I handle when the "tags" field has null value. I think thats the problem. Please help

I want to add multiple tags based on specific value of different fields. I have tried using the add\_tags functionality but that also replaces the old tags.

---

<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:** [December 16, 2018, 7:15pm UTC](https://discuss.elastic.co/t/please-help-i-cannot-add-two-tags-without-replacing-the-tag-that-added-first/160911/2 "2018-12-16T19:15:29Z")

</div>

Don't modify the `tags` field directly, use the `event.tag` method (`event.tag('PSY')` etc).

---

<div class="post-metadata">

**Author:** ![Harshet\_Jain](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@Harshet\_Jain](https://discuss.elastic.co/u/Harshet_Jain)\
**Post date:** [December 17, 2018, 5:26am UTC](https://discuss.elastic.co/t/please-help-i-cannot-add-two-tags-without-replacing-the-tag-that-added-first/160911/3 "2018-12-17T05:26:24Z")

</div>

Perfect! thank you very much . There isnt any documentation on the Event API page about this function 🙂

---

<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 14, 2019, 5:26am UTC](https://discuss.elastic.co/t/please-help-i-cannot-add-two-tags-without-replacing-the-tag-that-added-first/160911/4 "2019-01-14T05:26:29Z")

</div>

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