# How to run down source of mutate error?

**URL:** <https://discuss.elastic.co/t/how-to-run-down-source-of-mutate-error/285500>\
**Category:** Logstash\
**Created:** [September 29, 2021, 6:08pm UTC](https://discuss.elastic.co/t/how-to-run-down-source-of-mutate-error/285500 "2021-09-29T18:08:35Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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 29, 2021, 6:26pm UTC](https://discuss.elastic.co/t/how-to-run-down-source-of-mutate-error/285500/3 "2021-09-29T18:26:01Z")

</div>

To understand what is happening consider

```
input { generator { count => 1 lines => [''] } }
filter {
    mutate { add_field => { "foo1" => "" } }
    mutate { add_field => { "[foo1][bar]" => "1" } }
    mutate { add_field => { "foo" => "a" } }
    mutate { add_field => { "[foo][bar]" => "2" } }
}
output { stdout { codec => rubydebug { metadata => false } } }

```

That generates

> [2021-09-29T14:20:46,878][WARN][logstash.filters.mutate][main][7b4b29026fb3b4e2ca120f9681a9c336324b1e7c46bccdc1e02cc51bfc76e3ec] Exception caught while applying mutate filter {:exception=\>"Could not set field 'bar' on object '' to value '1'.This is probably due to trying to set a field like [foo][bar] = someValuewhen [foo] is not either a map or a string"}  
> [2021-09-29T14:20:46,886][WARN][logstash.filters.mutate][main][336b225f2b3d8066dd7abea8a0cd836e5705eb0605607d3262538797068ed604] Exception caught while applying mutate filter {:exception=\>"Could not set field 'bar' on object 'a' to value '2'.This is probably due to trying to set a field like [foo][bar] = someValuewhen [foo] is not either a map or a string"}

So you have a field that contains an empty string and you are trying to create another field nested within. Once a field is a string you cannot use this technique to make it an object with nested fields.

The error message is badly worded ("is not either a map or a string"), missing a space in "someValuewhen", and would be a lot more useful if it logged the name of the field rather than the value. Unfortunately by the time the code is down in [setChild](https://github.com/elastic/logstash/blob/0f433a08147d28ff2d00e9c9da317be71e5d3b2d/logstash-core/src/main/java/org/logstash/Accessors.java#L142) it no longer has the name.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-run-down-source-of-mutate-error/285500)._
