# Add field only if its does not exists?

**URL:** <https://discuss.elastic.co/t/add-field-only-if-its-does-not-exists/54894>\
**Category:** Logstash\
**Created:** [July 7, 2016, 4:00am UTC](https://discuss.elastic.co/t/add-field-only-if-its-does-not-exists/54894 "2016-07-07T04:00:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![memelet](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@memelet](https://discuss.elastic.co/u/memelet)\
**Post date:** [July 7, 2016, 4:00am UTC](https://discuss.elastic.co/t/add-field-only-if-its-does-not-exists/54894/1 "2016-07-07T04:00:59Z")

</div>

I expect this is common, but I can't seem to find any info on how to set a field /only/ if it does not already exist.

I have tried translate:

```
translate {
  field => "level"
  dictionary => [
    "DEBUG", "DEBUG",
    "INFO", "INFO",
    "WARN", "WARN",
    "ERR", "ERROR"
  ]
  fallback => "INFO"
  exact => true
}

```

But when 'level' does not exist the fallback does not trigger.

I've also tried:

```
  if "" in [level] {
    mutate { add_field => { "level" => "INFO" } }
  }

```

And

```
  if [level] == "" {
    mutate { add_field => { "level" => "INFO" } }
  }

```

Oh, and I also tried

```
translate {
  field => "level"
  dictionary => [
    "DEBUG", "DEBUG",
    "INFO", "INFO",
    "WARN", "WARN",
    "ERR", "ERROR",
    "", "INFO"
  ]
  exact => true
}
```

---

<div class="post-metadata">

**Author:** ![memelet](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@memelet](https://discuss.elastic.co/u/memelet)\
**Post date:** [July 7, 2016, 4:04am UTC](https://discuss.elastic.co/t/add-field-only-if-its-does-not-exists/54894/2 "2016-07-07T04:04:34Z")

</div>

Ok, I found it

```
  if ![level] {
    mutate { add_field => { "level" => "INFO" } }
  }
```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 7, 2016, 6:31am UTC](https://discuss.elastic.co/t/add-field-only-if-its-does-not-exists/54894/3 "2016-07-07T06:31:24Z")

</div>

> [@memelet](#):
>
> `if [level] bah blah`

Is all you should need for the comparison.

---

<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:** [July 6, 2017, 4:49am UTC](https://discuss.elastic.co/t/add-field-only-if-its-does-not-exists/54894/4 "2017-07-06T04:49:11Z")

</div>


