# Loop on list topic

**URL:** <https://discuss.elastic.co/t/loop-on-list-topic/176762>\
**Category:** Logstash\
**Created:** [April 14, 2019, 6:27am UTC](https://discuss.elastic.co/t/loop-on-list-topic/176762 "2019-04-14T06:27:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arp220](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arp220/32/84666_2.png) [@arp220](https://discuss.elastic.co/u/arp220)\
**Post date:** [April 14, 2019, 6:27am UTC](https://discuss.elastic.co/t/loop-on-list-topic/176762/1 "2019-04-14T06:27:23Z")

</div>

Hi.  
I have 30 topics kafka from server1 and I want to send all these topics to server2.  
my input config is:

```auto
input { 
  kafka { 
        bootstrap_servers => "192.168.1.101:9092" 
        group_id => "all_topic" 
        topics => ["topic1, topic2,topic3,......,topic30"] 
        auto_offset_reset => "earliest" 
        decorate_events => true 
  } 
} 

```

I want every topic send to new tpoic name

```auto
output { 
   if ([@metadata][kafka][topic] == "topic1") { 
     kafka { 
       bootstrap_servers => "192.168.1.102:9092" 
       topic_id => "new_topic1" 
       codec => json 
          } 
if ([@metadata][kafka][topic] == "topic2") { 
     kafka { 
       bootstrap_servers => "192.168.1.102:9092" 
       topic_id => "new_topic2" 
       codec => json 
          } 
    } 
} 

```

Now, If I want to continue this way, The file gets too big for 30 topics, There is a way to apply to everyone in a block. A loop in the output block.  
thanks.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 14, 2019, 12:13pm UTC](https://discuss.elastic.co/t/loop-on-list-topic/176762/2 "2019-04-14T12:13:30Z")

</div>

If the only thing that changes is the topic, how about using a [https://www.elastic.co/guide/en/logstash/current/plugins-filters-translate.html](https://www.elastic.co/guide/en/logstash/current/plugins-filters-translate.html) filter to do the mapping? Then you can reference the translation in the kafka output

```
topic_id => "%{translation}"
```

---

<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:** [May 12, 2019, 12:13pm UTC](https://discuss.elastic.co/t/loop-on-list-topic/176762/3 "2019-05-12T12:13:33Z")

</div>

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