Logstash optionally set output options

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:

...
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?

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

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