# Logstash optionally set output options

**URL:** <https://discuss.elastic.co/t/logstash-optionally-set-output-options/214504>\
**Category:** Logstash\
**Created:** [January 9, 2020, 10:40pm UTC](https://discuss.elastic.co/t/logstash-optionally-set-output-options/214504 "2020-01-09T22:40:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Riddhesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/riddhesh/32/47232_2.png) [@Riddhesh](https://discuss.elastic.co/u/Riddhesh)\
**Post date:** [January 9, 2020, 10:40pm UTC](https://discuss.elastic.co/t/logstash-optionally-set-output-options/214504/1 "2020-01-09T22:40:13Z")

</div>

Suppose I have some documents with join field, so they may have parent(e.g. [join\_field][parent]) field in them, so as per docs, I need to pass that to \_routing in logstash elasticsearch output:

```auto
...
output {
  elasticsearch {
    ...
    routing => "%{[join_field][parent]}"
  }
}

```

Now if there is no join\_field in the doc, above will set its routing to literally `%{[join_field][parent]}` in ES.  
Is there anyway I can make it optional so the ES output will have routing set only if [join\_field][parent] is there?  
Or only way here is to have if else condition on the field and have separate output for each(but it feels odd to have multiple ifs for many options)? Also can this have any performance issue?

```auto
...
output {
  if [join_field][parent] {
    elasticsearch {
      ...
      routing => "%{[join_field][parent]}"
    }
  } else { 
    elasticsearch {
      ...
    }
  }
}

```

---

<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:** [February 6, 2020, 10:40pm UTC](https://discuss.elastic.co/t/logstash-optionally-set-output-options/214504/2 "2020-02-06T22:40:22Z")

</div>

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