# Cannot reference a field inside string

**URL:** <https://discuss.elastic.co/t/cannot-reference-a-field-inside-string/212276>\
**Category:** Logstash\
**Created:** [December 18, 2019, 8:16am UTC](https://discuss.elastic.co/t/cannot-reference-a-field-inside-string/212276 "2019-12-18T08:16:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BerkayOzturk](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@BerkayOzturk](https://discuss.elastic.co/u/BerkayOzturk)\
**Post date:** [December 18, 2019, 8:16am UTC](https://discuss.elastic.co/t/cannot-reference-a-field-inside-string/212276/1 "2019-12-18T08:16:10Z")

</div>

Hello,

I'm trying to reference a field from a string inside the output section of my configuration. Instead of the field value, what I get is the literal representation of the string; in this case: '%{myfield}'. Here is the simplified version of my configuration containing only the related information:

```
input {
    tcp {
            ...
    }
}

filter {
    if [somefield] == "something" {
                ...
        if [somefield2] =~ someregex {
            ...
            mutate {
                rename => { "somefield3" => "myfield" }
            }
           ...
        } else {
            drop {}
        }

    }

}

output {
    if "_jsonparsefailure" in [tags] {
        ...
    } else {
        ...
        rabbitmq {
            ...
            message_properties => {
              "content_type" => "application/json"
              "priority" => 1
              "app_id" => "%{myfield}"
            }
            ...
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![BerkayOzturk](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@BerkayOzturk](https://discuss.elastic.co/u/BerkayOzturk)\
**Post date:** [December 23, 2019, 7:01am UTC](https://discuss.elastic.co/t/cannot-reference-a-field-inside-string/212276/2 "2019-12-23T07:01:13Z")

</div>

(bump) I'm still struggling with this issue. Any ideas?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 23, 2019, 7:27am UTC](https://discuss.elastic.co/t/cannot-reference-a-field-inside-string/212276/3 "2019-12-23T07:27:21Z")

</div>

That probably means that your mutate filter that creates the `myfield` field does not run (due to conditional) or that there at that point is no `somefield3` that can be renamed.

---

<div class="post-metadata">

**Author:** ![BerkayOzturk](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@BerkayOzturk](https://discuss.elastic.co/u/BerkayOzturk)\
**Post date:** [December 23, 2019, 7:34am UTC](https://discuss.elastic.co/t/cannot-reference-a-field-inside-string/212276/4 "2019-12-23T07:34:35Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> at there at that point is no `somefield3` that can be renamed.

Actualy `somefield3` exists and `rename` mutation renames it to `myfield`. I'm validating by parsing the JSON output. But I can't reference the field in a string for some reason.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 23, 2019, 7:36am UTC](https://discuss.elastic.co/t/cannot-reference-a-field-inside-string/212276/5 "2019-12-23T07:36:59Z")

</div>

It may be that the rabbitmq plugin does not support that.

---

<div class="post-metadata">

**Author:** ![BerkayOzturk](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@BerkayOzturk](https://discuss.elastic.co/u/BerkayOzturk)\
**Post date:** [December 23, 2019, 7:39am UTC](https://discuss.elastic.co/t/cannot-reference-a-field-inside-string/212276/6 "2019-12-23T07:39:41Z")

</div>

Seems like it. I'll open a feature request on GitHub.

EDIT: [Cannot reference a field inside string #25](https://github.com/logstash-plugins/logstash-integration-rabbitmq/issues/25)

---

<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:** [January 20, 2020, 7:49am UTC](https://discuss.elastic.co/t/cannot-reference-a-field-inside-string/212276/7 "2020-01-20T07:49:36Z")

</div>

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