2014-09-23 75 views
0

我是Logstash,elasticsearch的新手。Logstash配置条件

我有NodeJS应用程序,我发送日志槽温斯顿:Redis。我有不同类型的日志,如Requests,system等。我希望这些日志在ElasticSearch内部分开放置在index_type中。

我正在发送这些密钥fe。 :“网络:生产:请求”,“网络:生产:系统”,即时通讯发送JSON对象。

我的配置是:

的NodeJS(温斯顿Redis的客户端) - > Redis的 - > Logstash - >弹性搜索

它的工作好,除了index_types。

我有1个redis客户端(流/订阅),我想过滤这些日志取决于关键的价值,以不同的index_types内弹性搜索输出。

我尝试这样配置:

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" 
    } 
} 

所以问题是:

  1. 怎么办条件语句吧?

  2. ,如果你想根据条件

  3. 我不能有内部命令状态发送不同的索引你会如何处理? FE。 grok {if [key] ==“1”{}}?

+0

这是什么插入ES或者是你得到某种错误的? – Alcanzar 2014-09-23 14:16:59

回答

0

建议的解决方法:

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" 
    } 
    } 
}