elasticsearch 如何将不同的日志存储事件发送到不同的输出
logstash filter部分中有许多事件作为字段,这些字段是从消息字段中提取的,如下所示:elasticsearch 如何将不同的日志存储事件发送到不同的输出,elasticsearch,logstash,elasticsearch,Logstash,logstash filter部分中有许多事件作为字段,这些字段是从消息字段中提取的,如下所示: match=>[“消息”,“%{type1:f1}%{type2:f2}%{type3:f3}”] 目的是将f1、f2、f3发送到一个输出,仅将f1和f3发送到其他输出插件,以便: output { elasticsearch { action => "index" hosts => "localhost" index =>"
match=>[“消息”,“%{type1:f1}%{type2:f2}%{type3:f3}”]
目的是将f1、f2、f3发送到一个输出,仅将f1和f3发送到其他输出插件,以便:
output {
elasticsearch {
action => "index"
hosts => "localhost"
index =>"indx1-%{+YYYY-MM}"
.
}
}
output {
elasticsearch {
action => "index"
hosts => "localhost"
index =>"indx2-%{+YYYY-MM}"
}
}
问题是每个输出插件都涉及到所有事件,但我想处理哪些事件转到哪个输出插件。有可能做到这一点吗?我找到了一个解决方案,使用filebeat将数据转发到logstash。 如果运行两个filebeat实例和一个logstash实例,则每个filebeat将输入数据转发到同一个logstash,但类型不同,如:
document_type: type1
在logstash中,使用if子句执行适当的过滤器和输出:
filter {
if [type] == "type1" {
}
else {
}
}
output {
if [type] == "type1" {
elasticsearch {
action => "index"
hosts => "localhost"
index => "%{type}-%{+YYYY.MM}"
}
}
else {
elasticsearch {
action => "index"
hosts => "localhost"
index => "%{type}-%{+YYYY.MM}"
}
}
}
如果在“过滤器”部分中有两个不同的匹配模式,那么可以为每个匹配添加特定的“标记”。然后在输出部分使用如下内容:
if "matchtype1" in [tags] {
elasticsearch {
hosts => "localhost"
index => "indxtype1-%{+YYYY.MM}"
}
}
if "matchtype2" in [tags]{
elasticsearch {
hosts => "localhost"
index => "indxtype2-%{+YYYY.MM}"
}
}