如何在logstash conf

时间:2015-11-07 15:26:59

标签: elasticsearch logstash logstash-grok

我有两个名为access_loghttp_access_2015-03-06_log的文件,我想将文件的accesshttp_access_2015-03-06部分设置为索引。

我为类似问题阅读了一些答案,但我无法了解如何使用grok过滤器过滤文件路径并将其用作索引的参考。

以下是我的配置文件:

input {
  file {
    path => ["G:/logstash-1.5.0/bin/tmp/*_log"]
    start_position => "beginning"

  }
}

filter {
  if [path] =~ "access" {
    mutate { replace => { type => "apache_access" } }
    grok {
      match => { "message" => "%{COMBINEDAPACHELOG}" }
    }
    date {
      match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
    }
  } else if [path] =~ "error" {
    mutate { replace => { type => "apache_error" } }
  } else {
    mutate { replace => { type => "random_logs" } }
  }
}

output {
  elasticsearch { 
     action => "index"
     host => localhost
     index => "test" 
  }
  stdout { codec => rubydebug }
}

怎么做?

1 个答案:

答案 0 :(得分:0)

您正在设置“类型”字段。如果这足够好,您可以在输出{}节中引用它:

.

如果您想使用过滤器中的一些您不希望存储在elasticsearch中的信息,可以将其放在元数据字段中,例如:

index => "%{type}-%{+YYYY.MM.dd}"

然后以同样的方式引用它。