# Logstash - any best practices for reusing elasitcsearch outputs across pipelines?

**URL:** <https://discuss.elastic.co/t/logstash-any-best-practices-for-reusing-elasitcsearch-outputs-across-pipelines/297155>\
**Category:** Logs\
**Created:** [February 14, 2022, 2:38pm UTC](https://discuss.elastic.co/t/logstash-any-best-practices-for-reusing-elasitcsearch-outputs-across-pipelines/297155 "2022-02-14T14:38:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mybyte](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mybyte/32/99989_2.png) [@mybyte](https://discuss.elastic.co/u/mybyte)\
**Post date:** [February 14, 2022, 2:38pm UTC](https://discuss.elastic.co/t/logstash-any-best-practices-for-reusing-elasitcsearch-outputs-across-pipelines/297155/1 "2022-02-14T14:38:48Z")

</div>

We have a set-up with sort of a hierarchical flow in the pipelines. Depending on application/format they're being routed to a different pipeline. All pipelines use the same Elasticsearch cluster for output, but in some cases a different ilm\_rollover\_alias so we can define different retention policies based on data sources.

Is there any sort of elegant solution to store the hosts & credential in one location, but specify the rollover alias in each individual pipe? I wouldn't want to go through dozens of pipelines just to change a token or hostnames...

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [February 14, 2022, 2:51pm UTC](https://discuss.elastic.co/t/logstash-any-best-practices-for-reusing-elasitcsearch-outputs-across-pipelines/297155/2 "2022-02-14T14:51:18Z")

</div>

Maybe you can use the [Logstash Keystore](https://www.elastic.co/guide/en/logstash/current/keystore.html) or [Environment Variables](https://www.elastic.co/guide/en/logstash/current/environment-variables.html).

In my case I use environment variables in the file `/etc/sysconfig/logstash`.

For example, in the file I will have the variables:

```auto
ES_USERNAME=username
ES_PASSWORD=password
ES_NODES="https://node01:9200 https://node02:9200 https://nodeN:9200"

```

Then in the output I would have:

```auto
output {
    elasticsearch {
        hosts => ["${ES_NODES}"]
        index => "index-name"
        http_compression => true
        user => '${ES_USERNAME}'
        password => '${ES_PASSWORD}'
    }
}

```

You could do the same with the `logstash-keystore`, I prefer the file with environment variables because it is easier to automate.

Also, any change on the values of the variables or keystore would require a logstash restart.

But, this way you would still need to edit the pipelines to change the `ilm_rollover_alias`.

Unfortunatelly the `ilm_rollover_alias` [does not support](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-ilm_rollover_alias) dynamic variable substitution that would allow you to use a similar approach.

---

<div class="post-metadata">

**Author:** ![mybyte](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mybyte/32/99989_2.png) [@mybyte](https://discuss.elastic.co/u/mybyte)\
**Post date:** [February 18, 2022, 9:48am UTC](https://discuss.elastic.co/t/logstash-any-best-practices-for-reusing-elasitcsearch-outputs-across-pipelines/297155/3 "2022-02-18T09:48:40Z")

</div>

I'd love some way to define environment variables in logstash.yml that could be used in all the pipelines. Environment variables would require you to re-create containers, the keystore is even more bothersome to work with...

Following your suggestion, we did some automation around Bitbucket and Jenkins to roll out configuration changes in a simple manner. Would be awesome if all we needed to do in order to add or remove elastic nodes from pipelines was a simple change to a single yml and maybe a container restart.

---

<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:** [March 18, 2022, 9:49am UTC](https://discuss.elastic.co/t/logstash-any-best-practices-for-reusing-elasitcsearch-outputs-across-pipelines/297155/4 "2022-03-18T09:49:09Z")

</div>

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