说到elasticsearch,很多人对模板这个概念比较陌生,本人经过1年的elk运维及调优,分享一下自己的通用模板,一切设置都可以按我这个模板进行个性化的延伸,具体看各位的需求
{
"order": 0,"template": "test-*", 这个是模板匹配的index
"settings": {
"index": {
"routing": {
"allocation": {
"total_shards_per_node": "1" 这个值设定的是该index,在每个datanode的最大分片数(主要是为了防止一个Index的shards全部集中在一台机器上,导致该机器负载过高)
}
},
"refresh_interval": "30s", 刷新时间
"number_of_shards": "6", 最大分片数
"number_of_replicas": "0", 副本为0
"merge": {
"scheduler": {
"max_thread_count": "1" 机械硬盘的各位建议设置这个值,因为段合并非常消耗cpu,对机械硬盘也有一定的损耗,笔者的集群硬盘坏过2次
}
}
}
},
"mappings": {
"_default_": {
"dynamic_templates": [ 动态模板,没什么好说的
{
"strings": {
"mapping": {
"norms": false,
"type": "text",
"fields": {
"raw": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"match_mapping_type": "string"
}
}
],
"_all": {
"enabled": false 这个值一定要关闭,_all字段会产生占用较多磁盘,并且产生额外的cpu消耗
},
"properties": { 字段类型自定义,这个也没什么好说的,text类型不用管,按需设置number型和date型
"request_time": {
"type": "double",
"fields": {
"raw": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"request_length": {
"type": "long",
"fields": {
"raw": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"body_bytes_sent": {
"type": "long",
"fields": {
"raw": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"upstream_header_time": {
"type": "double",
"fields": {
"raw": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"upstream_response_time": {
"type": "double",
"fields": {
"raw": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"bytes_sent": {
"type": "long",
"fields": {
"raw": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}
},
"aliases": {} 别名的设置,建议大家使用脚本定期管理别名,不然会很乱
}