# Logstash kafka rename topic name

**URL:** <https://discuss.elastic.co/t/logstash-kafka-rename-topic-name/124334>\
**Category:** Logstash\
**Created:** [March 16, 2018, 4:48pm UTC](https://discuss.elastic.co/t/logstash-kafka-rename-topic-name/124334 "2018-03-16T16:48:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajkrishmoorthy](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@rajkrishmoorthy](https://discuss.elastic.co/u/rajkrishmoorthy)\
**Post date:** [March 16, 2018, 4:48pm UTC](https://discuss.elastic.co/t/logstash-kafka-rename-topic-name/124334/1 "2018-03-16T16:48:25Z")

</div>

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" }  
}  
}

---

<div class="post-metadata">

**Author:** ![yaauie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaauie/32/23363_2.png) [@yaauie](https://discuss.elastic.co/u/yaauie)\
**Post date:** [March 17, 2018, 4:35am UTC](https://discuss.elastic.co/t/logstash-kafka-rename-topic-name/124334/2 "2018-03-17T04:35:12Z")

</div>

> [@rajkrishmoorthy](#):
>
> i tried following config it seems not working

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?

---

<div class="post-metadata">

**Author:** ![rajkrishmoorthy](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@rajkrishmoorthy](https://discuss.elastic.co/u/rajkrishmoorthy)\
**Post date:** [March 17, 2018, 5:39pm UTC](https://discuss.elastic.co/t/logstash-kafka-rename-topic-name/124334/3 "2018-03-17T17:39:25Z")

</div>

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]}

---

<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:** [April 14, 2018, 5:39pm UTC](https://discuss.elastic.co/t/logstash-kafka-rename-topic-name/124334/4 "2018-04-14T17:39:51Z")

</div>

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