# How to add a tag based on input data

**URL:** <https://discuss.elastic.co/t/how-to-add-a-tag-based-on-input-data/214713>\
**Category:** Logstash\
**Created:** [January 11, 2020, 9:47pm UTC](https://discuss.elastic.co/t/how-to-add-a-tag-based-on-input-data/214713 "2020-01-11T21:47:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![debojyoti\_bandyopadh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debojyoti_bandyopadh/32/60663_2.png) [@debojyoti\_bandyopadh](https://discuss.elastic.co/u/debojyoti_bandyopadh)\
**Post date:** [January 11, 2020, 9:47pm UTC](https://discuss.elastic.co/t/how-to-add-a-tag-based-on-input-data/214713/1 "2020-01-11T21:47:57Z")

</div>

Hello, I am a beginner in logstash and currently learning the basics. I am stuck while solving a problem. Basically my input(to logstash) can be a series of Alphabets like below:

a  
b  
a  
c  
d

I want to add a tag "A" if the data read is "a" also i need to Ensure that the input data is tagged with type as "test" , and write the output to the file output.txt in the path usr/share/logstash. I understand that i can tag the input data in stdin and then use the file plugin to output the data to output.txt file but i just cant figure out how i can add the tag "A" if the data read is "a". Please advise.

---

<div class="post-metadata">

**Author:** ![rugenl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rugenl/32/12887_2.png) [@rugenl](https://discuss.elastic.co/u/rugenl)\
**Post date:** [January 12, 2020, 1:01am UTC](https://discuss.elastic.co/t/how-to-add-a-tag-based-on-input-data/214713/2 "2020-01-12T01:01:22Z")

</div>

Something like this in the filter section:

```
filter {
  if "a" in [message] {
      mutate { add_tag => "a" }
   }
}
```

---

<div class="post-metadata">

**Author:** ![debojyoti\_bandyopadh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debojyoti_bandyopadh/32/60663_2.png) [@debojyoti\_bandyopadh](https://discuss.elastic.co/u/debojyoti_bandyopadh)\
**Post date:** [January 12, 2020, 10:52am UTC](https://discuss.elastic.co/t/how-to-add-a-tag-based-on-input-data/214713/3 "2020-01-12T10:52:58Z")

</div>

Thanks a lot, exactly what i needed.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 12, 2020, 3:04pm UTC](https://discuss.elastic.co/t/how-to-add-a-tag-based-on-input-data/214713/4 "2020-01-12T15:04:19Z")

</div>

Note that 'if "a" in [message]' is substring matching. If you want an exact match then use 'if "a" == [message]'

---

<div class="post-metadata">

**Author:** ![Ramicoh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramicoh/32/61017_2.png) [@Ramicoh](https://discuss.elastic.co/u/Ramicoh)\
**Post date:** [January 12, 2020, 5:15pm UTC](https://discuss.elastic.co/t/how-to-add-a-tag-based-on-input-data/214713/5 "2020-01-12T17:15:52Z")

</div>

I see you already got a great answer to your question, but I wanted to add that if you're new to Logstash, you may also want to have a look at some open source parsers, such as [https://github.com/empow/logstash-parsers/](https://github.com/empow/logstash-parsers/).

We've been dealing with log parsing for years and it can get very tricky to nail the real meaning of the data. These kind of parses interface into Logstash as `.conf` files, and can greatly help you consolidate and normalize numerous log dumps into information that can be effectively used (using the Elastic Common Schema, MITRE rationale etc.). See [https://blog.empow.co/loganalysis](https://blog.empow.co/loganalysis).

---

<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:** [February 9, 2020, 5:15pm UTC](https://discuss.elastic.co/t/how-to-add-a-tag-based-on-input-data/214713/6 "2020-02-09T17:15:53Z")

</div>

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