我有兩個名爲access_log
和http_access_2015-03-06_log
的文件,我想將access
和http_access_2015-03-06
部分文件設置爲索引。如何在logstash conf中建立索引時添加文件名
我讀了類似問題的一些答案,但我無法得到如何使用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 }
}
如何可以做到?
可能重複的[Logstash:如何添加文件名作爲字段?](http://stackoverflow.com/questions/22916200/logstash-how-to-add-file-name-as-a-field) –