# Setting a field on Input and Referencing on output

**URL:** <https://discuss.elastic.co/t/setting-a-field-on-input-and-referencing-on-output/88482>\
**Category:** Logstash\
**Created:** [June 6, 2017, 10:32pm UTC](https://discuss.elastic.co/t/setting-a-field-on-input-and-referencing-on-output/88482 "2017-06-06T22:32:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![seth.yes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seth.yes/32/11788_2.png) [@seth.yes](https://discuss.elastic.co/u/seth.yes)\
**Post date:** [June 6, 2017, 10:32pm UTC](https://discuss.elastic.co/t/setting-a-field-on-input-and-referencing-on-output/88482/1 "2017-06-06T22:32:16Z")

</div>

I'm using the HTTP Logstash (5.4.0) input plugin to receive json input data. I'm having users send data to a different port depending on whether it's test, staging or production data. I then need to reference that field in the output in order to populate the correct index.

The issue currently is that while the field I create is added and populated correctly, my output filter appears to always jump to the 'else' catchall of the output.

```auto
input {
  http {
    port => 8080
    type => ["maps-iei"]
    add_field => { "raw_message" => "message" }
    add_field => { "iei-type" => "production" }
    id => "maps-iei-prod"
  }
}
input {
  http {
    port => 8081
    type => ["maps-ic"]
    add_field => { "raw_message" => "message" }
    add_field => { "iei-type" => "staging" }
    id => "maps-iei-staging"
  }
}
input {
  http {
    port => 8082
    type => ["maps-test"]
    add_field => { "raw_message" => "%{message}" }
    add_field => { "iei-type" => "test" }
    id => "maps-iei-test"
    response_headers => {
      "Access-Control-Allow-Origin" => "*"
      "Content-Type" => "application/json"
      "Access-Control-Allow-Headers" => "Origin, X-Requested-With, Content-Type, Accept"
    }
  }
}
output {
  if [iei_type] in ["production", "maps-iei-prod"] {
    elasticsearch {
      hosts => ["127.0.0.1:9200"]
      index => "maps-iei-%{+YYYY.MM.dd}"
      sniffing => "false"
    }
  }
  else if [iei_type] == "staging" {
    elasticsearch {
      hosts => ["127.0.0.1:9200"]
      index => "maps-ic-%{+YYYY.MM.dd}"
      sniffing => "false"
    }
  }
  else if [iei_type] == "test" {
    elasticsearch {
      hosts => ["127.0.0.1:9200"]
      index => "maps-ic-%{+YYYY.MM.dd}"
      sniffing => "false"
    }
  }
  else {
    elasticsearch {
      hosts => ["127.0.0.1:9200"]
      index => "maps-iei-%{+YYYY.MM.dd}"
      sniffing => "false"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Jaxon\_Kochel](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@Jaxon\_Kochel](https://discuss.elastic.co/u/Jaxon_Kochel)\
**Post date:** [June 7, 2017, 8:24pm UTC](https://discuss.elastic.co/t/setting-a-field-on-input-and-referencing-on-output/88482/2 "2017-06-07T20:24:54Z")

</div>

I believe you have your if statements backwards, they should be reversed to something like

> ```
> if ["production", "maps-iei-prod"] in [iei_type] {
> elasticsearch {
> hosts => ["127.0.0.1:9200"]
> index => "maps-iei-%{+YYYY.MM.dd}"
> sniffing => "false"
> }
> }
> else if "staging" in [iei_type] {
> elasticsearch {
> hosts => ["127.0.0.1:9200"]
> index => "maps-ic-%{+YYYY.MM.dd}"
> sniffing => "false"
> }
> }
> else if "test" in [iei_type] {
> elasticsearch {
> hosts => ["127.0.0.1:9200"]
> index => "maps-ic-%{+YYYY.MM.dd}"
> sniffing => "false"
> }
> }
> else {
> elasticsearch {
> hosts => ["127.0.0.1:9200"]
> index => "maps-iei-%{+YYYY.MM.dd}"
> sniffing => "false"
> }
> 
> ```

---

<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:** [June 11, 2017, 8:10pm UTC](https://discuss.elastic.co/t/setting-a-field-on-input-and-referencing-on-output/88482/3 "2017-06-11T20:10:39Z")

</div>

There's nothing wrong with the order of the operands in the conditional but the field is spelled `iei-type` in `add_field` but `iei_type` in the conditionals.

---

<div class="post-metadata">

**Author:** ![seth.yes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seth.yes/32/11788_2.png) [@seth.yes](https://discuss.elastic.co/u/seth.yes)\
**Post date:** [June 12, 2017, 5:38pm UTC](https://discuss.elastic.co/t/setting-a-field-on-input-and-referencing-on-output/88482/4 "2017-06-12T17:38:40Z")

</div>

Good call, thanks @magnusbaeck

---

<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 10, 2017, 5:38pm UTC](https://discuss.elastic.co/t/setting-a-field-on-input-and-referencing-on-output/88482/5 "2017-07-10T17:38:41Z")

</div>

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