一、引子
目前的数据同步,mappings映射会自动创建,但是分词不会,还是会使用默认的,而我们需要中文分词器,这个时候就需要自定义模板功能来设置分词了。
二、设置自定义模板
1.查看Logstash默认模板POSTMAN
GET /_template/logstash
2.复制后修改模板
在/usr/local/logstash-6.4.3/sync/下创建文件logstash-ik.json,内容为:
{
"order": 0,
"version": 1,
"index_patterns": ["*"],
"settings": {
"index": {
"refresh_interval": "5s"
}
},
"mappings": {
"_default_": {
"dynamic_templates": [
{
"message_field": {
"path_match": "message",
"match_mapping_type": "string",
"mapping": {
"type": "text",
"norms": false
}
}
},
{
"string_fields": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "text",
"norms": false,
"analyzer": "ik_max_word",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
],
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "keyword"
},
"geoip": {
"dynamic": true,
"properties": {
"ip": {
"type": "ip"
},
"location": {
"type": "geo_point"
},
"latitude": {
"type": "half_float"
},
"longitude": {
"type": "half_float"
}
}
}
}
}
},
"aliases": {}
}
3.修改同步的配置文件/usr/local/logstash-6.4.3/sync/logstash-db-sync.conf
# 定义模板名称
template_name => "myik"
# 模板所在位置
template => "/usr/local/logstash-6.4.3/sync/logstash-ik.json"
# 重写模板
template_overwrite => true
# 默认为true,false关闭logstash自动管理模板功能,如果自定义模板,则设置为false
manage_template => false
4.重新运行
./logstash -f /usr/local/logstash-6.4.3/sync/logstash-db-sync.conf