Logstash kafka rename topic name

below is my logstash config, i need to rename topic to new topicname, how can i achieve that ?, i tried following config it seems not working

input {
kafka {
bootstrap_servers => "boostrap1:9092"
topics => ["global-heart-beat"]
client_id => "logstash-hostname1"
group_id => "logstash_indexer"
decorate_events => "true"
}
}

filter {
json {
source => "message"
}
mutate {
replace => { "[@metadata][kafka][topic]" => "%[@metadata][kafka][topic]-test" }
}
}

What happened? How is this different from what you expected to happen?

Why are you trying to change the metadata record of which topic the message came from? Or, is that what you are trying to do?

here is my updated config; i was trying to extract topic name and output to a file, i was expecting to see topic name to ouput file as part of message , here is the config and output i see, my ultimate objective is to rename the topic name, but for now i would like to atleast see if i can get topic name for later reference in output section

input {
kafka {
bootstrap_servers => "bootstrap:9092"
topics => ["global-heart-beat"]
client_id => "logstash-hostname1"
group_id => "logstash_indexer"
decorate_events => true
add_field => { "[topic_name]" => "%{[@metadata][kafka][topic]}" }
}
}

output {
stdout { codec => rubydebug { metadata => true } }
file {
path => "/var/tmp/logstash.output"
codec => line { format => "custom format: %{message} %{topic_name}" }
}
}

Output: iam expecting to see topic 'global-heart-beat' reflected

$ cat /var/tmp/logstash.output
custom format: msg:hello world %{[@metadata][kafka][topic]}

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