學習課程連接《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" } } } ] } }