# The Logstash configuration item is written repeatedly

**URL:** <https://discuss.elastic.co/t/the-logstash-configuration-item-is-written-repeatedly/238771>\
**Category:** Logstash\
**Created:** [June 26, 2020, 3:15am UTC](https://discuss.elastic.co/t/the-logstash-configuration-item-is-written-repeatedly/238771 "2020-06-26T03:15:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard-Tang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richard-tang/32/71152_2.png) [@Richard-Tang](https://discuss.elastic.co/u/Richard-Tang)\
**Post date:** [June 26, 2020, 3:15am UTC](https://discuss.elastic.co/t/the-logstash-configuration-item-is-written-repeatedly/238771/1 "2020-06-26T03:15:37Z")

</div>

Distinguish according to Tags

But need to repeat it in if  
"hosts "，"user"，"password"

I have a lot of "if" that I have to write multiple times

```auto
output {
    if "server4-apache-access" in [tags] {
        elasticsearch {
            hosts => ["http://localhost:9200"]
            index => "server4-apache-access-%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
            user => "elastic"
            password => "elastic"
        }
    }
    if "server4-apache-error" in [tags] {
        elasticsearch {
            hosts => ["http://localhost:9200"]
            index => "server4-apache-error-%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
            user => "elastic"
            password => "elastic"
        }
    }
}

```

That's the solution I've found so far

But I don't think this is particularly good 😝 😝

[https://www.elastic.co/guide/en/logstash/current/environment-variables.html](https://www.elastic.co/guide/en/logstash/current/environment-variables.html)

---

<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 24, 2020, 3:15am UTC](https://discuss.elastic.co/t/the-logstash-configuration-item-is-written-repeatedly/238771/2 "2020-07-24T03:15:43Z")

</div>

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