Can we set kafka output topic dynamically in filebeat?

(Jaskirat Singh) #1

Hey all,

I am using filebeat to read log files and output them to kafka.My log file contains lines like this:
:2018/06/28 10:59:37 {"data":"test message","topic":"account_4"}
and filebeat read it like this:

"@timestamp": "2018-06-28T10:12:00.648Z",
"@metadata": {
"beat": "filebeat",
"type": "doc",
"version": "6.3.0"
"message": ":2018/06/28 10:07:33 {"data":"test message","topic":"account_4"}"

what i want to do is that read this topic input nested in message field and set it to kafka output in filebeat.yml i.e output.kafka which is not working for me.

here is my filebeat.yml


  • type: log
    enabled: true
    • /etc/test/log/*.log
  • drop_fields:
    fields: ["beat", "source", "host", "input", "prospector", "offset"]
    hosts: ["localhost:9092"]
    topic: '%{[topic]}'
    username: "test"
    password: "test"

(Andrew Kroh) #2

Dynamic topic selection is supported (docs), but the field you use to specifiy the topic need to be in the event (i.e. you need to have the data in a structured format first).

So before you can reference topic you need to parse it out of the message field. Up until Filebeat 6.3.0 this would not have been possible unless your data was JSON. But now there is a dissect processor.

You'll can try using the dissect processor followed the decode_json_fields processor. You need to separate that leading timestamp in the message field from the JSON content. Then parse the JSON. And finally you'll be able to reference the topic value contained in your message.

(Jaskirat Singh) #3

Thanks @andrewkroh But i think the version supporting this feature is not released yet.

(Mark Walkom) #4

6.3 was released a fortnight ago :slight_smile:

(Jaskirat Singh) #5

(Jaskirat Singh) #6

dissect processor is not there in 6.3 docs.

(Andrew Kroh) #7

Sorry, looks like I had remembered the wrong target version for release of dissect. It's targeted for 6.4

If you want to try it out there are snapshot builds available based the master branch.

(system) #8

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