Logstash condition statement

Hi, Below is my logstash output config file, I am using too many if, else if conditional statements in the code. Is it possible to do a case statement like in ruby or something which will reduce the repetition.

output {
if [type] == "my-report" {
elasticsearch {
hosts => ["localhost:9200"]
user => "myid"
password => "mypassword"
index => "my-reports-%{+YYYY.MM.dd}"
}
} else if [type] =~ "beat." {
elasticsearch {
hosts => ["localhost:9200"]
user => "myid"
password => "mypassword"
index => "beat-%{+YYYY.MM.dd}"
}
} else if [type] =~ "kafka.
" {
elasticsearch {
hosts => ["localhost:9200"]
user => "myid"
password => "mypassword"
index => "kafka-%{+YYYY.MM.dd}"
}
} else {
elasticsearch {
hosts => ["localhost:9200"]
user => "logstash_internal"
password => "logstashpassword"
index => "logs-%{type}-%{+YYYY.MM.dd}"
}
}
}

No, the if conditional is the only support control structure.

1 Like

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