# Unable to convert a field from string to integer that is dynamically generated in Logstash filter

**URL:** https://discuss.elastic.co/t/unable-to-convert-a-field-from-string-to-integer-that-is-dynamically-generated-in-logstash-filter/300224
**Category:** Logstash
**Created:** [March 21, 2022, 3:53pm UTC](https://discuss.elastic.co/t/unable-to-convert-a-field-from-string-to-integer-that-is-dynamically-generated-in-logstash-filter/300224 "2022-03-21T15:53:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Usman18](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@Usman18](https://discuss.elastic.co/u/Usman18)
#### Post date: [March 21, 2022, 3:53pm UTC](https://discuss.elastic.co/t/unable-to-convert-a-field-from-string-to-integer-that-is-dynamically-generated-in-logstash-filter/300224/1 "2022-03-21T15:53:40Z")

</div>

I am adding a field in my event data point in Logstash filter. The name of the field is created dynamically based on the value of the other field. The code can be seen below which I am using to add this field

```auto
mutate {
    add_field => { "[data][queue-average-length][%{[data][queue-average-length][unit]}]" => "%{[data][queue-average-length][value]}"}    
}

```

Actually, I am trying to add a field in data.queue-average-length object and the name of the newly added field will be decided based on the value that is present in the data.queue-average-length.unit field. The value that is stored in newly created field is string but it contains an integer and I want to convert in into integer. In the next step, I used this code to convert string value to integer but I am getting \_mutate\_error tag.

```auto
mutate {
    convert => {"[data][queue-average-length][%{[data][queue-average-length][unit]}]" => "integer" }
}

```

If in the above code, instead of this expression %{[data][queue-average-length][unit]} I hardcode the value that is present in this field data.queue-average-length.unit, I do not get any error and value is successfully converted into integer. Can anyone guide me in this regard? Thanks

---

<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: [March 21, 2022, 6:45pm UTC](https://discuss.elastic.co/t/unable-to-convert-a-field-from-string-to-integer-that-is-dynamically-generated-in-logstash-filter/300224/2 "2022-03-21T18:45:03Z")

</div>

> [@Usman18](#):
>
> Can anyone guide me in this regard?

See [this](https://discuss.elastic.co/t/cannot-convert-created-field-to-integer/299005/6) post. You cannot use a sprintf reference in the source of a convert.

---

<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: [April 18, 2022, 6:45pm UTC](https://discuss.elastic.co/t/unable-to-convert-a-field-from-string-to-integer-that-is-dynamically-generated-in-logstash-filter/300224/3 "2022-04-18T18:45:56Z")

</div>

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