# Referencing an Environment Variable when existing field content is part of the name

**URL:** https://discuss.elastic.co/t/referencing-an-environment-variable-when-existing-field-content-is-part-of-the-name/158709
**Category:** Logstash
**Created:** [November 29, 2018, 8:22am UTC](https://discuss.elastic.co/t/referencing-an-environment-variable-when-existing-field-content-is-part-of-the-name/158709 "2018-11-29T08:22:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Krobar](https://avatars.discourse-cdn.com/v4/letter/k/57b2e6/32.png) [@Krobar](https://discuss.elastic.co/u/Krobar)
#### Post date: [November 29, 2018, 8:22am UTC](https://discuss.elastic.co/t/referencing-an-environment-variable-when-existing-field-content-is-part-of-the-name/158709/1 "2018-11-29T08:22:59Z")

</div>

Is this possible?

I have tried various configs including the one below:  
mutate {  
add\_field =\> {  
"BRAND\_VERSION\_NAME" =\> "BRAND\_VERSION\_%{Region}\_%{Language}"  
"BRAND\_VERSION" =\> "'${%{BRAND\_VERSION\_NAME}}'"  
}  
}

BRAND\_VERSION\_NAME does contain the correct environment variable name but the variable name just gets printed for BRAND\_VERSION (Rather than the contents of the environment variable)

---

<div class="post-metadata">

### Author: ![Eniqmatic](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Eniqmatic](https://discuss.elastic.co/u/Eniqmatic)
#### Post date: [November 29, 2018, 8:25am UTC](https://discuss.elastic.co/t/referencing-an-environment-variable-when-existing-field-content-is-part-of-the-name/158709/2 "2018-11-29T08:25:37Z")

</div>

That's because I think you are adding them within the same add\_field function, so technically the field does not exist yet when processing. Try splitting it out into a different mutate filter to test first. Also do you need the "$" in the brand\_version field name?

---

<div class="post-metadata">

### Author: ![Krobar](https://avatars.discourse-cdn.com/v4/letter/k/57b2e6/32.png) [@Krobar](https://discuss.elastic.co/u/Krobar)
#### Post date: [November 29, 2018, 11:30am UTC](https://discuss.elastic.co/t/referencing-an-environment-variable-when-existing-field-content-is-part-of-the-name/158709/3 "2018-11-29T11:30:14Z")

</div>

Thank you for the reply. I tried separating out the adds as hown below but the result is still the same:  
add\_field =\> {  
"BRAND\_VERSION\_NAME" =\> "BRAND\_VERSION\_%{Region}\_%{Language}"  
}  
add\_field =\> {  
"BRAND\_VERSION" =\> "'${%{BRAND\_VERSION\_NAME}}'"  
}

Any more ideas on how to fix this?

---

<div class="post-metadata">

### Author: ![Eniqmatic](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Eniqmatic](https://discuss.elastic.co/u/Eniqmatic)
#### Post date: [November 29, 2018, 12:12pm UTC](https://discuss.elastic.co/t/referencing-an-environment-variable-when-existing-field-content-is-part-of-the-name/158709/4 "2018-11-29T12:12:37Z")

</div>

Try them in different mutate filters as above! Also I ask again, did you mean to put the dollar symbol in the field?

```
mutate {
  add_field => {
    "BRAND_VERSION_NAME" => "BRAND_VERSION_%{Region}_%{Language}"
  }
}
mutate {
  add_field =&gt; {
    "BRAND_VERSION" => "'${%{BRAND_VERSION_NAME}}'"
  }
}
```

---

<div class="post-metadata">

### Author: ![Krobar](https://avatars.discourse-cdn.com/v4/letter/k/57b2e6/32.png) [@Krobar](https://discuss.elastic.co/u/Krobar)
#### Post date: [November 29, 2018, 12:48pm UTC](https://discuss.elastic.co/t/referencing-an-environment-variable-when-existing-field-content-is-part-of-the-name/158709/5 "2018-11-29T12:48:58Z")

</div>

Thanks again but no luck. I think I do want the dollar symbol because I think this needs to be there to refer to the Environment variable.

So for example the fields could be:  
Region="cn"  
Lanuage="en"

I would be looking to get the content of an environment variable called BRAND\_VERSION\_cn\_en.

---

<div class="post-metadata">

### Author: ![Eniqmatic](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Eniqmatic](https://discuss.elastic.co/u/Eniqmatic)
#### Post date: [November 29, 2018, 1:29pm UTC](https://discuss.elastic.co/t/referencing-an-environment-variable-when-existing-field-content-is-part-of-the-name/158709/6 "2018-11-29T13:29:21Z")

</div>

No to refer to the field it is just %{BRAND\_VERSION\_NAME}

---

<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: [December 27, 2018, 1:29pm UTC](https://discuss.elastic.co/t/referencing-an-environment-variable-when-existing-field-content-is-part-of-the-name/158709/7 "2018-12-27T13:29:22Z")

</div>

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