您可以根據其中一個字段的值使用索引名稱中的模式。這裏我們使用type
字段的值,以命名索引:
output {
stdout {codec => rubydebug}
elasticsearch {
host => "localhost"
protocol => "http"
index => "%{type}_indexer"
}
}
您也可以使用多個elasticsearch
輸出到同一ES主機或不同的ES主機:
output {
stdout {codec => rubydebug}
elasticsearch {
host => "localhost"
protocol => "http"
index => "trial_indexer"
}
elasticsearch {
host => "localhost"
protocol => "http"
index => "movie_indexer"
}
}
或者也許你想給你的路線文件,基於一些變量不同的指標:
output {
stdout {codec => rubydebug}
if [type] == "trial" {
elasticsearch {
host => "localhost"
protocol => "http"
index => "trial_indexer"
}
} else {
elasticsearch {
host => "localhost"
protocol => "http"
index => "movie_indexer"
}
}
}
UPDATE
的語法已經改變一點點Logstash 2和5:
output {
stdout {codec => rubydebug}
if [type] == "trial" {
elasticsearch {
hosts => "localhost:9200"
index => "trial_indexer"
}
} else {
elasticsearch {
hosts => "localhost:9200"
index => "movie_indexer"
}
}
}
來源
2015-11-20 06:54:55
Val
你指的「類型」中的「輸入」部分聲明?如果是這樣,是否有一種方法可以用作我登錄的實際redis事件中的字段之一? – Kepedizer
@Kepedizer'type'可以在任何地方定義,無論是在輸入部分還是在過濾器部分。唯一的問題[在你的其他問題](http://stackoverflow.com/questions/41531883/logstash-wont-pass-index-from-redis)是一個錯字,你需要使用'%{index}'而不是'$ {index}' – Val
@Val我在試圖在Logstash文檔中追查這個問題的答案時非常糟糕,所以非常感謝您對它進行清理。爲StackOverflow得分另一個。 –