栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

logstash 5.0.1:为多个kafka输入主题设置elasticsearch多个索引输出

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

logstash 5.0.1:为多个kafka输入主题设置elasticsearch多个索引输出

首先,您需要添加

decorate_events
kafka
输入中才能知道消息来自哪个主题

input {  kafka {    bootstrap_servers => "zookeper_address"    topics => ["topic1","topic2"]    decorate_events => true  }}

然后,您有两个选择,都涉及条件逻辑。首先是通过引入一个过滤器来根据主题名称添加正确的索引名称。为此,您需要添加

filter {   if [kafka][topic] == "topic1" {      mutate {         add_field => {"[@metadata][index]" => "index1"}      }   } else {      mutate {         add_field => {"[@metadata][index]" => "index2"}      }   }   # remove the field containing the decorations, unless you want them to land into ES   mutate {      remove_field => ["kafka"]   }}output {  elasticsearch {    hosts => ["localhost:9200"]    index => "%{[@metadata][index]}"    prec => "json"    document_id => "%{id}"  }}

然后第二个选择是直接在输出部分执行if / else,就像这样(但是其他

kafka
字段将落入ES中):

output {   if [@metadata][kafka][topic] == "topic1" {     elasticsearch {       hosts => ["localhost:9200"]       index => "index1"       prec => "json"       document_id => "%{id}"     }   } else {     elasticsearch {       hosts => ["localhost:9200"]       index => "index2"       prec => "json"       document_id => "%{id}"     }   }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/386655.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号