# Filebeat Kafka topic mappings

**URL:** <https://discuss.elastic.co/t/filebeat-kafka-topic-mappings/233584>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [May 20, 2020, 5:53pm UTC](https://discuss.elastic.co/t/filebeat-kafka-topic-mappings/233584 "2020-05-20T17:53:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darshan\_B\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darshan_b_m/32/48742_2.png) [@Darshan\_B\_M](https://discuss.elastic.co/u/Darshan_B_M)\
**Post date:** [May 20, 2020, 5:53pm UTC](https://discuss.elastic.co/t/filebeat-kafka-topic-mappings/233584/1 "2020-05-20T17:53:48Z")

</div>

Hi I am trying to setup filebeat to send events to Kafka and have a requirement that I will need to send events from different apps to a different topic.

I tried to set the configs as mentioned in the documentation(`https://www.elastic.co/guide/en/beats/filebeat/7.2/kafka-output.html#topics-option-kafka`) but nothing works and it always falls back to the default topic. Could someone please shed more light as the documentation doesn't show any example around this.

My filebeat.yaml is as below.

Case 1: (Doesn't work)

```auto
    filebeat.inputs:
    - type: container
      paths:
        - /var/lib/docker/containers/*/*.log
      fields:
        log_type: containerlogs
        group_name: kafka_default_group
      processors:
        - add_kubernetes_metadata:
            host: ${NODE_NAME}
            cluster: ${CLUSTER_NAME}
            matchers:
            - logs_path:
                logs_path: "/var/lib/docker/containers/*/"

    output.kafka:
      codec.json:
        pretty: true
        escape_html: false
      hosts: ['broker1:9092', 'broker2:9092']
    topic: Kafka_default_topic  
    topics:
        topic: logs_topic_0
        when.equals:
          appname: app1
        topic: logs_topic_2
        when.equals:
          appname: app1
       
      partition.round_robin:
        reachable_only: false
    required_acks: 1
    max_message_bytes: 10485760

```

Case 2: (Doesn't work)

```auto
filebeat.inputs:
- type: container
  paths:
    - /var/lib/docker/containers/*/*.log
  fields:
    log_type: containerlogs
    group_name: kafka_default_group

  processors:
    - add_kubernetes_metadata:
        host: ${NODE_NAME}
        cluster: ${CLUSTER_NAME}
        matchers:
        - logs_path:
            logs_path: "/var/lib/docker/containers/*/"

output.kafka:
  codec.json:
    pretty: true
    escape_html: false
  hosts: ['broker1:9092', 'broker2:9092']
  topics:
  - topic: '%{[fields.appname]}'
    mappings:
      app1: logs_topic_0
      app2: logs_topic_1
    default: kafka_default_topic
  partition.round_robin:
    reachable_only: false
required_acks: 1
max_message_bytes: 10485760

```

---

<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:** [June 17, 2020, 5:53pm UTC](https://discuss.elastic.co/t/filebeat-kafka-topic-mappings/233584/2 "2020-06-17T17:53:55Z")

</div>

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