# Direct different log to different Kafka topic

**URL:** <https://discuss.elastic.co/t/direct-different-log-to-different-kafka-topic/137873>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [June 28, 2018, 10:15pm UTC](https://discuss.elastic.co/t/direct-different-log-to-different-kafka-topic/137873 "2018-06-28T22:15:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niloo\_F](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Niloo\_F](https://discuss.elastic.co/u/Niloo_F)\
**Post date:** [June 28, 2018, 10:15pm UTC](https://discuss.elastic.co/t/direct-different-log-to-different-kafka-topic/137873/1 "2018-06-28T22:15:32Z")

</div>

Hi,  
How can I direct logs from different inputs (all same type: log) to different topics in my kafka cluster.

Thanks  
N.

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [June 28, 2018, 10:55pm UTC](https://discuss.elastic.co/t/direct-different-log-to-different-kafka-topic/137873/2 "2018-06-28T22:55:48Z")

</div>

The topic can be set by referencing a variable `topic: '%{[fields.topic]}'`. Or there is a more expressive syntax that can be used with `topics`. See [kafka output config](https://www.elastic.co/guide/en/beats/filebeat/master/kafka-output.html#_literal_topic_literal).

Example 1:

```auto
filebeat.inputs:
- paths: [/web/*.log]
  fields:
    topic: web

output.kafka.topic: '%{[fields.topic]}'

```

Example 2:

```auto
filebeat.inputs:
- paths: [/web/*.log]
  fields:
    topic: web

output.kafka.topic: mydefault
output.kafka.topics:
- when.contains.source: web
  topic: web
- when.contains.message: login
  topic: authentication

```

---

<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 26, 2018, 10:56pm UTC](https://discuss.elastic.co/t/direct-different-log-to-different-kafka-topic/137873/3 "2018-07-26T22:56:05Z")

</div>

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