# Logstash conditional not being evaluated

**URL:** <https://discuss.elastic.co/t/logstash-conditional-not-being-evaluated/198288>\
**Category:** Logstash\
**Created:** [September 5, 2019, 4:04pm UTC](https://discuss.elastic.co/t/logstash-conditional-not-being-evaluated/198288 "2019-09-05T16:04:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvoros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bvoros/32/5246_2.png) [@bvoros](https://discuss.elastic.co/u/bvoros)\
**Post date:** [September 5, 2019, 4:04pm UTC](https://discuss.elastic.co/t/logstash-conditional-not-being-evaluated/198288/1 "2019-09-05T16:04:04Z")

</div>

Hello All,

I am trying to make changes to the format of a document and there are conditionals that do not take effect.

Original document:

```auto
{
  "@timestamp": "2019-09-02T13:10:39.931Z",
  "tags": [
    "beats_input_codec_plain_applied"
  ],
  "host": {
    "name": "ip-xx-xx-xx-xx"
  },
  "log": {
    "file": {
      "path": "/opt/xxxxxxxx/logs/xxxxxx.log"
    },
    "offset": 31891946
  },
  "message": "some logline",
  "@version": "1",
  "input": {
    "type": "log"
  },
  "ecs": {
    "version": "1.0.1"
  },
  "agent": {
    "hostname": "ip-xx-xx-xx-xx",
    "id": "c61120bc-f353-4159-95a3-59145bf7d7fd",
    "type": "filebeat",
    "version": "7.3.1",
    "ephemeral_id": "d51a5206-3bfa-4d8c-be2d-0c18f13adad4"
  }
}

```

filter:

```auto
filter{
    if 'filebeat' in [tags] or 'beats_input_codec_plain_applied' in [tags] {
        if [name] in [host] {
            mutate {
                add_field => { "host_name" => "%{[host][name]}" }
            }
            mutate {
                remove_field => ["host"]
            }
            mutate {
                rename => { "host_name" => "host" }
            }
        }
        if [file] in [log] {
            mutate {
                add_field => { "source_file" => "%{[log][file][path]}" }
            }
            mutate {
                remove_field => ["log"]
            }
        }
        if [type] in [input] {
            mutate {
                add_field => { "type" => "filebeat" }
            }
            mutate {
                remove_field => ["input"]
            }
        }
        mutate {
            remove_field => ["ecs", "agent"]
        }
    }
}

```

resulting document:

```auto
{
  "message": "some logline",
  "@timestamp": "2019-09-02T13:10:39.931Z",
  "input": {
    "type": "log"
  },
  "host": {
    "name": "ip-xx-xx-xx-xx"
  },
  "log": {
    "file": {
      "path": "/opt/xxxxxxxx/logs/xxxxxx.log"
    },
    "offset": 31891946
  },
  "tags": [
    "filebeat",
    "beats_input_codec_plain_applied"
  ],
  "@version": "1"
}

```

Apart from the last mutate that drops "ecs" and "agent" none of the other conditions appear to be evaluated.

What am I doing wrong?

---

<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:** [September 5, 2019, 5:14pm UTC](https://discuss.elastic.co/t/logstash-conditional-not-being-evaluated/198288/2 "2019-09-05T17:14:30Z")

</div>

> [@bvoros](#):
>
> if [file] in [log] {

To test if the field [log][file] exists use

```
if [log][file] {

```

Similarly your other tests.

---

<div class="post-metadata">

**Author:** ![bvoros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bvoros/32/5246_2.png) [@bvoros](https://discuss.elastic.co/u/bvoros)\
**Post date:** [September 6, 2019, 8:00am UTC](https://discuss.elastic.co/t/logstash-conditional-not-being-evaluated/198288/3 "2019-09-06T08:00:36Z")

</div>

Thanks again!

---

<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:** [October 4, 2019, 8:14am UTC](https://discuss.elastic.co/t/logstash-conditional-not-being-evaluated/198288/4 "2019-10-04T08:14:37Z")

</div>

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