You can't have conditionals inside the plugin definitions. Do this instead:
if [type] == "metricsets" {
elasticsearch {
hosts => "localhost"
index => "metricbeat-%{+YYYY.MM.dd}"
}
} else {
elasticsearch {
hosts => "localhost"
index => "logstash-%{+YYYY.MM.dd}"
}
}