我是Logstash的新手,弹性搜索。
我有NodeJS应用程序,在那里我通过Winston:Redis发送日志。我有不同类型的日志,如请求、系统等。我希望这些日志在ElasticSearch内的单独index_type中。
我把这些钥匙寄给你"web:production:request"、"web:pproduction:system"和im发送JSON obejcts。
我的配置是:
NodeJS(Winston Redis客户端)->Redis->Logstash->Elastic search
除了index_types之外,它的工作效果很好。
我有一个redis客户端(流/子订阅),我想根据弹性搜索输出中不同索引类型的键值来过滤这些日志。
我尝试了这个配置:
input {
redis {
host => "127.0.0.1"
data_type => "pattern_channel"
key => "web:production:*"
codec => json
}
filter {
if [key] == "web:production:request" {
alter {
add_field => { "index_type" => "request" }
}
}
if [key] == "web:production:system" {
alter {
add_field => { "index_type" => "system" }
}
}
}
output {
elasticsearch {
index => "web-production-%{+YYYY.MM.dd}"
index_type => "%{index_type}"
# THIS IS NOT WORKING
protocol => "http"
}
}
所以问题是:
条件句如何正确?
如果您想根据条件发送不同的索引,您将如何进行
我不能在命令中有条件吗?fe。grok{if[key]=="1"{}}?
解决方法的建议:
output {
if [index_type] == "request"{
elasticsearch {
index => "web-production-request%{+YYYY.MM.dd}"
protocol => "http"
}
}
if [index_type] == "system"{
elasticsearch {
index => "web-production-system%{+YYYY.MM.dd}"
protocol => "http"
}
}
}