# Assign event from kafka to ES index based on topic name

**URL:** <https://discuss.elastic.co/t/assign-event-from-kafka-to-es-index-based-on-topic-name/48210>\
**Category:** Elasticsearch\
**Created:** [April 22, 2016, 11:30pm UTC](https://discuss.elastic.co/t/assign-event-from-kafka-to-es-index-based-on-topic-name/48210 "2016-04-22T23:30:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stecino](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@stecino](https://discuss.elastic.co/u/stecino)\
**Post date:** [April 22, 2016, 11:30pm UTC](https://discuss.elastic.co/t/assign-event-from-kafka-to-es-index-based-on-topic-name/48210/1 "2016-04-22T23:30:59Z")

</div>

Hello,

I have

input {

kafka {  
zk\_connect =\> "list of zoo keepers"  
white\_list =\> "topbeat-wc1|filebeat-wc1|winlogbeat-wc1"  
decorate\_events =\> true  
codec =\> plain  
}  
}

This is the standard out

{  
"message" =\> "2016-04-22T23:01:43.437Z blah %{message}",  
"@version" =\> "1",  
"@timestamp" =\> "2016-04-22T23:01:44.747Z",  
"kafka" =\> {  
"msg\_size" =\> 50,  
"topic" =\> "topbeat-wc1",  
"consumer\_group" =\> "logstash",  
"partition" =\> 0,  
"key" =\> nil  
}  
}  
{  
"message" =\> "2016-04-22T23:01:40.680Z blah 04/22/2016 16:01:38|spLIST\_GetUpdatedListings\_153|Listing Server|78|0",  
"@version" =\> "1",  
"@timestamp" =\> "2016-04-22T23:01:44.747Z",  
"kafka" =\> {  
"msg\_size" =\> 110,  
"topic" =\> "filebeat-wc1",  
"consumer\_group" =\> "logstash",  
"partition" =\> 6,  
"key" =\> nil  
}  
}

I am trying to use the value of the topic and assign it to index in the output section

output {

```
     elasticsearch {
         hosts => [list of data nodes]
         index => %{topic}
                 }

```

It's currently not working. Should I do this using metadata, or there is a simpler way that I am not seeing at the moment

---

<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:** [July 5, 2017, 10:56pm UTC](https://discuss.elastic.co/t/assign-event-from-kafka-to-es-index-based-on-topic-name/48210/2 "2017-07-05T22:56:54Z")

</div>


