之前在配置从logstash写数据到elasticsearch时,指定单个数据模板没有问题。可是在配置多个数据模板时候,总是不成功,后来找了非常多资料,最终找到解决的方法,就是要多加一个配置项: template_name ,切该名字必须所有为小写。
參考配置信息:
output {
if [type] == "log_01" {
elasticsearch {
cluster => 'elasticsearch'
host => 'x.x.x.x'
index => 'log_01-%{+YYYY-MM-dd}'
port => '9300'
workers => 1
template => "/data/logstash/conf/template_01.json"
template_name => "template_01.json"
template_overwrite => true
}
}
if [type] == "log_02" {
elasticsearch {
cluster => 'elasticsearch'
host => 'x.x.x.x'
index => 'log_02-%{+YYYY-MM-dd}'
port => '9300'
workers => 1
template => "/data/logstash/conf/template_02.json"
template_name => "template_01.json"
template_overwrite => true
}
}
}