指定一个默认的映射文件,将其命名未test.json。位于/opt/logstash/config/templates/下。内容大致如下
{ "template" : "logstash", "settings" : { "index.number_of_shards" : 2, "number_of_replicas" : 1, "index.refresh_interval" : "30s" }, "mappings" : { "_default_" : { "_all" : {"enabled" : true}, "dynamic_templates" : [ { "string_fields" : { "match" : "*", "match_mapping_type" : "string", "mapping" : { "type" : "string", "index" : "not_analyzed", "omit_norms" : true, "doc_values": true, "fields" : { "raw" : {"type": "string", "index" : "not_analyzed", "ignore_above" : 256,"doc_values": true} } } } } ], "properties" : { "@version": { "type": "string", "index": "not_analyzed" }, "geoip" : { "type" : "object", "dynamic": true, "path": "full", "properties" : { "location" : { "type" : "geo_point" } } } } } } }Logstash文件配置
output { elasticsearch { host => "IP:Port" #ES的服务器地址 protocol => "http" #使用的协议,默认可能会使用Node,具体还要看机器的环境 index => "logstash-%{+YYYY.MM.dd}" document_type => "test" #索引的类型,旧的配置会使用index_type,但是这个字段在新版本中已经被舍弃了,推荐使用document_type manage_template => true #注意默认为true,一定不能设置为false template_overwrite => true #如果设置为true,模板名字一样的时候,新的模板会覆盖旧的模板 template_name => "myLogstash" #注意这个名字是用来查找映射配置的,尽量设置成全局唯一的 template => "/opt/logstash/config/templates/test.json" #映射配置文件的位置 }