# \[logstash 5.3\]\[plugin output elasticsearch\] Using env variable in conf file

**URL:** <https://discuss.elastic.co/t/logstash-5-3-plugin-output-elasticsearch-using-env-variable-in-conf-file/81472>\
**Category:** Logstash\
**Created:** [April 6, 2017, 12:52pm UTC](https://discuss.elastic.co/t/logstash-5-3-plugin-output-elasticsearch-using-env-variable-in-conf-file/81472 "2017-04-06T12:52:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fares](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fares/32/45311_2.png) [@fares](https://discuss.elastic.co/u/fares)\
**Post date:** [April 6, 2017, 12:52pm UTC](https://discuss.elastic.co/t/logstash-5-3-plugin-output-elasticsearch-using-env-variable-in-conf-file/81472/1 "2017-04-06T12:52:30Z")

</div>

Hello,

I'm trying to use env var in my conf file

> ```
> elasticsearch{
> ...
> hosts => ${ES_HOST}
> }
> 
> ```

My var contains host:port type value, ie localhost:9200  
Got this error  
`ERROR logstash.agent - Cannot load an invalid configuration {:reason=>"bad URI(is not URI?):`

Thanks for your help

---

<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:** [April 7, 2017, 5:08am UTC](https://discuss.elastic.co/t/logstash-5-3-plugin-output-elasticsearch-using-env-variable-in-conf-file/81472/2 "2017-04-07T05:08:22Z")

</div>

I don't think the `hosts` option is subject to such expansions. Supporting event-dependent `%{fieldname}` expansions would be a bad idea, and since they go along with `${envname}` expansions you don't get the latter either.

---

<div class="post-metadata">

**Author:** ![fares](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fares/32/45311_2.png) [@fares](https://discuss.elastic.co/u/fares)\
**Post date:** [April 7, 2017, 1:05pm UTC](https://discuss.elastic.co/t/logstash-5-3-plugin-output-elasticsearch-using-env-variable-in-conf-file/81472/3 "2017-04-07T13:05:13Z")

</div>

Thanks @magnusbaeck for your reply.

Could you please elaborate why hosts option is not subject to such expansions ?

Since we could do so in 2.x logstash version and in other ouptut plugins like Kafka in logstash 5.3 ?

Thank you 🙂

---

<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:** [April 10, 2017, 5:24am UTC](https://discuss.elastic.co/t/logstash-5-3-plugin-output-elasticsearch-using-env-variable-in-conf-file/81472/4 "2017-04-10T05:24:27Z")

</div>

> Could you please elaborate why hosts option is not subject to such expansions ?

Because `%{fieldname}` expansions in `hosts` could mean that Logstash would have to connect to a different host for every event. There are probably ways to solve that in a reasonable way but I suspect nobody has wanted to spend the time doing that.

> Since we could do so in 2.x logstash version

Oh? That's surprising.

> and in other ouptut plugins like Kafka in logstash 5.3 ?

Which option for the kafka output?

---

<div class="post-metadata">

**Author:** ![fares](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fares/32/45311_2.png) [@fares](https://discuss.elastic.co/u/fares)\
**Post date:** [April 10, 2017, 8:42am UTC](https://discuss.elastic.co/t/logstash-5-3-plugin-output-elasticsearch-using-env-variable-in-conf-file/81472/5 "2017-04-10T08:42:41Z")

</div>

Hello Magnus,

> Which option for the kafka output?

Here is the kafka output in my logstash 5.3 conf  
I'm setting an env variable KAFKA\_SERVERS="host1:9092,host2:9092,host3:9092"

```
 kafka{
                        codec=>"json"
                        topic_id=>"tpc_ex"
                        bootstrap_servers=>"${KAFKA_SERVERS}"
                }

```

It works well.

---

<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:** [May 8, 2017, 8:50am UTC](https://discuss.elastic.co/t/logstash-5-3-plugin-output-elasticsearch-using-env-variable-in-conf-file/81472/6 "2017-05-08T08:50:42Z")

</div>

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