# Using hash variable in output

**URL:** <https://discuss.elastic.co/t/using-hash-variable-in-output/96143>\
**Category:** Logstash\
**Created:** [August 7, 2017, 6:37pm UTC](https://discuss.elastic.co/t/using-hash-variable-in-output/96143 "2017-08-07T18:37:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Exocomp](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Exocomp](https://discuss.elastic.co/u/Exocomp)\
**Post date:** [August 7, 2017, 6:37pm UTC](https://discuss.elastic.co/t/using-hash-variable-in-output/96143/1 "2017-08-07T18:37:06Z")

</div>

Is it possible to use hash as a variable in the output section in logstash. Here is a simple example to demonstrate what I mean:

```
ruby {
	code => "
		count = { 'metric1' => 1, 'metric2' => 2 };
		event.set('statsd_count', count);
	"
}

```

So basically create a "statsd\_count" variable that is a hash having a couple values.

```
output {
  statsd {
    host => "statsd.example.org"
    count => "%{statsd_count}"
  }
}

```

Then use the statsd\_count as a variable in the count property. I get an error "This setting must be a hash".

This is a simple example, but in practice the hash values can be different based on the event type so in order to handle that case I'd have to use multiple if statements in the output section each having a separate statsd block which I'd like to avoid.

---

<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:** [September 4, 2017, 6:37pm UTC](https://discuss.elastic.co/t/using-hash-variable-in-output/96143/2 "2017-09-04T18:37:23Z")

</div>

Closed on September 4, 2017, 6:37pm UTC

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