学习课程连接《Elasticsearch核心技术与实战》app
Mappings
和Settings
,并按照必定的规则,自动匹配到新建立的索引上
merge
在一块儿order
的数值,控制merging
的过程#示例一:对全部的索引有效 PUT _template/template_default { "index_patterns": ["*"], "order" : 0, "version": 1, "settings": { "number_of_shards": 1, "number_of_replicas":1 } }
#示例二:对以test开头索引有效 PUT /_template/template_test { "index_patterns" : ["test*"], "order" : 1, "settings" : { "number_of_shards": 1, "number_of_replicas" : 2 }, "mappings" : { "date_detection": false, "numeric_detection": true } }
#查看template信息 GET /_template/template_default GET /_template/temp*
#删除template信息 DELETE /_template/template_default DELETE /_template/template_test
settings
和mappings
order
数值低的 IndexTemplate 中的设定order
数值高的 IndexTemplate 中的设定,以前的设定会被覆盖settings
和mappings
,并覆盖以前模板中的设定Dynamic Template 是定义在具体索引mappings
中的,根据Elasticsearch识别的数据类型,结合字段名称,来动态设定字段类型:elasticsearch
keyword
,或者关闭keyword
字段is
开头的字段设置成boolean
long_
开头的都设置成long
类型#示例一:Dynaminc Mapping 根据类型和字段名 PUT my_index { "mappings": { "dynamic_templates": [ { "strings_as_boolean": { "match_mapping_type": "string", "match":"is*", "mapping": { "type": "boolean" } } }, { "strings_as_keywords": { "match_mapping_type": "string", "mapping": { "type": "keyword" } } } ] } }
#示例二: PUT my_index { "mappings": { "dynamic_templates": [ { "full_name": { "path_match": "name.*", "path_unmatch": "*.middle", "mapping": { "type": "text", "copy_to": "full_name" } } } ] } }