# Add\_field not performing variable substitution

**URL:** https://discuss.elastic.co/t/add-field-not-performing-variable-substitution/53629
**Category:** Logstash
**Created:** [June 22, 2016, 8:54am UTC](https://discuss.elastic.co/t/add-field-not-performing-variable-substitution/53629 "2016-06-22T08:54:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jeffsmartpipe](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jeffsmartpipe](https://discuss.elastic.co/u/jeffsmartpipe)
#### Post date: [June 22, 2016, 8:54am UTC](https://discuss.elastic.co/t/add-field-not-performing-variable-substitution/53629/1 "2016-06-22T08:54:26Z")

</div>

Hi all,

Newbie to logstash here but I'm sure this should work. I am creating a metric and need to be able to split by http result code. The result code is stored in %{rcode}. In the below the variable is being substituted in the metric name correctly but not in the add\_field method.

Any ideas?  
Thanks  
Jeff

filter {  
if [type] == "heeaccesslogs" {  
metrics {  
meter =\> "heeevents\_rcode\_%{rcode}"  
add\_tag =\> "metric"  
add\_field =\> { "rcode" =\> "%{rcode}" }  
add\_field =\> { "type" =\> "heemetric" }  
}  
}  
}

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [July 4, 2016, 6:48pm UTC](https://discuss.elastic.co/t/add-field-not-performing-variable-substitution/53629/2 "2016-07-04T18:48:45Z")

</div>

Show us an example of the kind of event you want to process (preferably using a `stdout { codec => rubydebug }` output).

> add\_field =\> { "rcode" =\> "%{rcode}" }

This doesn't make sense. You're trying to assign a field to its current value.

---

<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-not-performing-variable-substitution/53629/3 "2017-07-06T04:49:38Z")

</div>


