简体   繁体   English

logstash kafka使用不同的编解码器输入了多个主题

[英]logstash kafka input multiple topics with different codecs

this is my logstash conf 这是我的logstash conf

input {
  kafka {
    bootstrap_servers => "127.0.0.1:9092"
    topics => ["filebeat", "access"]
    group_id => "test-consumer-group"
    consumer_threads => 1
    decorate_events => true
  }
}

I have two topics but I want to use different codec for diffrent topic. 我有两个主题,但我想对不同的主题使用不同的编解码器。 how can I do this? 我怎样才能做到这一点?

I try to add 我尝试添加

    if ([topic] == "filebeat") {
      codec => "json"
    }

in the kafka input conf, the the logstash returns me errors. 在kafka输入conf中,logstash返回错误。

Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of #, => at line 6, column 8 (byte 143) after input {\n  kafka {\n    bootstrap_servers => \"127.0.0.1:9092\"\n    topics => [\"filebeat\", \"access\"]\n    group_id => \"test-consumer-group\"\n    if "

You can create 2 separate kafka inputs with each a different codec. 您可以使用每个不同的编解码器创建2个单独的kafka输入。

One other option is to add a filter that parses the json object depending on the the topic 另一种选择是添加一个过滤器,该过滤器根据主题来解析json对象

filter {
  if([topic] == "filebeat") {
    json {
      source => "message"
    }
  }
}

for more info check: https://www.elastic.co/guide/en/logstash/current/plugins-filters-json.html 有关更多信息,请检查: https : //www.elastic.co/guide/zh-CN/logstash/current/plugins-filters-json.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM