Filebeat kafka out plugin error when configuring multiple topics using regex

I am trying to output file to different topic using regex, but the following config does not work:

filebeat.inputs:
- type: log
  enabled: true
  paths:
      - ~/1.log

output.kafka:
    enabled: true
    hosts: ["localhost:9092"]
    topic: "default"
    codec.format:
        string: '%{[message]}'
    topics:
        - topic: "type1"
          when.regexp.message: "\[type1\].*"
        - topic: "type2"
          when.regexp.message: "\[type2\].*"

the error message is

Exiting: error loading config file: yaml: line 20: found unknown escape character

OS: Mac
filebeat version: 6.5, 7.5
Kafka version : 2.3.1

When I tried reproducing this with your posted configuration, I got a similar error but on a different line:

Exiting: error loading config file: yaml: line 15: found unknown escape character

To fix that I used single quotes ' for quoting the regular expressions on line 15 and 17. After I did that, I was able to start up Filebeat without any YAML validation errors.

Your error messages mentions line 20 but the posted configuration does not have 20 lines in it.

sorry, when I copy the config I remove some comments. And single quote does work, thanks very much.

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