# Logstash - send to different elasticsearch dependent on var

**URL:** https://discuss.elastic.co/t/logstash-send-to-different-elasticsearch-dependent-on-var/75992
**Category:** Logstash
**Created:** [February 22, 2017, 7:30am UTC](https://discuss.elastic.co/t/logstash-send-to-different-elasticsearch-dependent-on-var/75992 "2017-02-22T07:30:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![joshg](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@joshg](https://discuss.elastic.co/u/joshg)
#### Post date: [February 22, 2017, 7:30am UTC](https://discuss.elastic.co/t/logstash-send-to-different-elasticsearch-dependent-on-var/75992/1 "2017-02-22T07:30:05Z")

</div>

I have 2 elasticsearch environments. 1 for dev and 1 for prod.

I want log stash to send to the correct environment dependent on an environment variable

This is what my current output config looks like

```
output {
  stdout {
    codec => dots {}
  }

  IF {environment} == "live"  
  elasticsearch {
    hosts => ["live-env-url:9200"]
    user => "username"
    password => "password"
    index => "logs-%{environment}-%{application}[%{+YYYY-MM-dd}]"
  }
  ELSE 
  elasticsearch {
    hosts => ["dev-env-url:9200"]
    user => "username"
    password => "password"
    index => "logs-%{environment}-%{application}[%{+YYYY-MM-dd}]"
  }
}

```

Help, please and 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: [February 22, 2017, 8:39am UTC](https://discuss.elastic.co/t/logstash-send-to-different-elasticsearch-dependent-on-var/75992/2 "2017-02-22T08:39:59Z")

</div>

```nohighlight
if [environment] == "live" {
  elasticsearch {
    hosts => ["live-env-url:9200"]
    user => "username"
    password => "password"
    index => "logs-%{environment}-%{application}[%{+YYYY-MM-dd}]"
  }
} else {
  elasticsearch {
    hosts => ["dev-env-url:9200"]
    user => "username"
    password => "password"
    index => "logs-%{environment}-%{application}[%{+YYYY-MM-dd}]"
  }
}

```

---

<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 22, 2017, 8:40am UTC](https://discuss.elastic.co/t/logstash-send-to-different-elasticsearch-dependent-on-var/75992/3 "2017-03-22T08:40:00Z")

</div>

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