Elasticsearch的Index Template和Dynamic Template
一、什么是 Index Templates
帮助设定 Mappings 和 Setting,并按照一定的规则,自动匹配到新创建的索引之上
- 模板仅在一个索引被新创建时,才会产生作用。修改模板不会影响已创建的索引
- 你可以设定多个索引模板,这些设置会被“merge”在一起
- 你可以指定“oder”的数值,控制“merging”的过程
二、Index Template 的工作方式
当一个索引被创建时
- 应用 Elasticsearch 默认的 setting 和 mapping
- 应用 order 数值低的 Index Template 中的设定
- 应用 order 高的 Index Template 中的设定,之前的设定会被覆盖
- 应用创建索引时,用户所指定的 Setting 和 Mapping,并覆盖之前模板中的设定
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
}
}
三、什么是 Dynamic Template
根据 Elasticsearch 识别的数据类型,结合字段名称,来动态设定字段类型
- 所有的字符串类型都设定成 Keyword,或者关闭 Keyword 字段
- is 开头的字段都设置成 boolean
- long_开头的都设置成 long 类型
四、Dynamic Template 设定
- Dynamic Template 是定义在某个索引的 Mapping 中
- Template 有一个名称
- 匹配规则是一个数组
- 为匹配到字段设置 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"
}
}
}
]
}
}
IVF stimulation involves using various subcutaneous injection medications such as Follistim or Gonal F and Menopur online cialis pharmacy Spectral index for assessment of differential protein expression in shotgun proteomics
generic cialis 5mg Suggest medication for ovulation