# Logstash dynamic elasticsearch hosts output

**URL:** https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615
**Category:** Logstash
**Created:** [June 5, 2018, 12:38pm UTC](https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615 "2018-06-05T12:38:36Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [June 5, 2018, 12:38pm UTC](https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615/1 "2018-06-05T12:38:36Z")

</div>

```
output { 
  elasticsearch { 
     ...
     hosts => ["%{ELASTICSEARCH_URL}"]
  } 
}

```

Is that possible? Because it is not working within Logstash 6.1.4.

---

<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: [June 5, 2018, 1:44pm UTC](https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615/2 "2018-06-05T13:44:32Z")

</div>

That references the ELASTICSEARCH\_URL field of the current event. Did you want that, or do you want ${ELASTICSEARCH\_URL}, which reference an environment variable?

---

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [June 5, 2018, 1:57pm UTC](https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615/3 "2018-06-05T13:57:24Z")

</div>

I want ELASTICSEARCH\_URL field of the current event.

---

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [June 5, 2018, 2:27pm UTC](https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615/4 "2018-06-05T14:27:16Z")

</div>

Because I am using a condicional in the filter plugin:

```
if ([headers][request_uri] == "/fep") {
  mutate { add_field => { "ELASTICSEARCH_URL" => "https://e95444bf74974e44b8c8011d48c96f25.rb-elasticsearch.de.bosch.com:9243" } }
}

```

just if the field [headers][request\_uri] is equal /fep that I add to the hosts field the value of the ELASTICSEARCH\_URL variable.

---

<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: [June 5, 2018, 2:39pm UTC](https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615/5 "2018-06-05T14:39:02Z")

</div>

I would have expected it to work, but you are right, it does not.

```
exception=>"Java::JavaNet::URISyntaxException", :message=>"Malformed escape pair at index 0: %{ELASTICSEARCH_URL}", :backtrace=>["java.net.URI$Parser.fail(java/net/URI.java:2848)"
```

---

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [June 5, 2018, 2:41pm UTC](https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615/6 "2018-06-05T14:41:48Z")

</div>

Yes, and I really need that in that way... ☹

---

<div class="post-metadata">

### Author: ![EloaCardoso](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@EloaCardoso](https://discuss.elastic.co/u/EloaCardoso)
#### Post date: [June 5, 2018, 2:46pm UTC](https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615/7 "2018-06-05T14:46:44Z")

</div>

@magnusbaeck: Do you have any idea about that?

---

<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 3, 2018, 2:46pm UTC](https://discuss.elastic.co/t/logstash-dynamic-elasticsearch-hosts-output/134615/8 "2018-07-03T14:46:47Z")

</div>

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