# Using Field Data in Output Hosts?

**URL:** <https://discuss.elastic.co/t/using-field-data-in-output-hosts/277594>\
**Category:** Logstash\
**Created:** [July 1, 2021, 8:03pm UTC](https://discuss.elastic.co/t/using-field-data-in-output-hosts/277594 "2021-07-01T20:03:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_L](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_l/32/83661_2.png) [@Dan\_L](https://discuss.elastic.co/u/Dan_L)\
**Post date:** [July 1, 2021, 8:03pm UTC](https://discuss.elastic.co/t/using-field-data-in-output-hosts/277594/1 "2021-07-01T20:03:33Z")

</div>

Hello, I am trying to use the value of a field when I am defining hosts in logstash output. I've been able to do this in other logstash outputs like index. Is this possible?  
For example:

```auto
output {
elasticsearch {
hosts => ["%{host1}", "%{host2}"]
}
}

```

I get an error about a malformed escape pair when I try this. I am doing something very similar in other fields without issue.

---

<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:** [July 1, 2021, 8:09pm UTC](https://discuss.elastic.co/t/using-field-data-in-output-hosts/277594/2 "2021-07-01T20:09:57Z")

</div>

> [@Dan\_L](#):
>
> Is this possible?

No. An elasticsearch output establishes a connection to the elasticsearch instance during initialization. It cannot reconnect to a different instance for each event based on a field on that event.

---

<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 29, 2021, 8:10pm UTC](https://discuss.elastic.co/t/using-field-data-in-output-hosts/277594/3 "2021-07-29T20:10:52Z")

</div>

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