# Adding conditional tags or fields

**URL:** https://discuss.elastic.co/t/adding-conditional-tags-or-fields/253890
**Category:** Beats
**Tags:** filebeat
**Created:** [October 31, 2020, 7:34am UTC](https://discuss.elastic.co/t/adding-conditional-tags-or-fields/253890 "2020-10-31T07:34:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zoulja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zoulja/32/77747_2.png) [@zoulja](https://discuss.elastic.co/u/zoulja)
#### Post date: [October 31, 2020, 7:34am UTC](https://discuss.elastic.co/t/adding-conditional-tags-or-fields/253890/1 "2020-10-31T07:34:07Z")

</div>

Hello.  
I need Filebeat 7.9.2 to add tags based on content.  
What I've tried:

```auto
  - add_tags:
        when:
          contains:
           request:"/image/"
        tags: [image]
  - add_tags:
        when:
          contains:
           request:"/api/"
        tags: [api]

```

Not sure whether it works or not, Filebeat fails to start

> Exiting: Failed to start crawler: starting input failed: Error while initializing input: wrong type, expect map accessing 'filebeat.inputs.1.processors.2.add\_tags.when.contains'

Please advise what's the issue here and how conditional tagging can be implemented in proper way

---

<div class="post-metadata">

### Author: ![jsoriano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsoriano/32/27920_2.png) [@jsoriano](https://discuss.elastic.co/u/jsoriano)
#### Post date: [November 3, 2020, 6:24pm UTC](https://discuss.elastic.co/t/adding-conditional-tags-or-fields/253890/2 "2020-11-03T18:24:04Z")

</div>

Hey @zoulja,

Configuration looks fine, but the error seems to indicate that there is some typo. Try to add a space between the value and the key of `request`:

```auto
  - add_tags:
        when:
          contains:
            request: "/image/"
        tags: [image]
  - add_tags:
        when:
          contains:
            request: "/api/"
        tags: [api]

```

Please also review the indentation, try to avoid the use of tabs.

If nothing works, share the whole configuration file to see if there is something weird.

---

<div class="post-metadata">

### Author: ![zoulja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zoulja/32/77747_2.png) [@zoulja](https://discuss.elastic.co/u/zoulja)
#### Post date: [November 4, 2020, 9:25am UTC](https://discuss.elastic.co/t/adding-conditional-tags-or-fields/253890/3 "2020-11-04T09:25:45Z")

</div>

Thanks, it really was space issue

---

<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: [December 2, 2020, 11:25am UTC](https://discuss.elastic.co/t/adding-conditional-tags-or-fields/253890/4 "2020-12-02T11:25:55Z")

</div>

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