Elasticsearch template(待续...)
动态模板
Dynamic templates allow you to define custom mappings that can be applied to dynamically added fields based on:
- the datatype detected by Elasticsearch, with
match_mapping_type
. - the name of the field, with
match
andunmatch
ormatch_pattern
. - the full dotted path to the field, with
path_match
andpath_unmatch
.
The original field name {name}
and the detected datatype {dynamic_type
} template variables can be used in the mapping specification as placeholders.
动态模板允许你基于以下条件来对动态增加的字段的映射进行自定义:
1. match_mapping_type 定义 ES 自动检测的数据类型
2. match、unmatch 或 match_pattern 匹配字段名称
3. path_match、path_unmatch 定义字段的全路径
参数说明
template
settings
注意事项
dynamic_templates 类型为数组,多个匹配条件要写为数据的不同元素
示例
为所有索引 (index) 的所有类型 (type) 的所有字符串类型字段(field)都设置为 not_analyzed。
curl -XPUT 'localhost:9200/_template/all' -d ' { "order": 0, "template": "*", "settings": { "index.number_of_shards": "1" }, "mappings": { "_default_": { "dynamic_templates": [ { "string": { "mapping": { "index": "not_analyzed", "type": "string" }, "match_mapping_type": "string",
"match": "field_name*"
} } ] } }, "aliases": {} } } '