Index Template和Dynamic Template
什么是Index template
- Index Templates - 帮助设定Mapping 和 Settings,并按照一定的规则,自动匹配到新创建的索引上
- 模板仅在一个索引被新创建时,才会产生作用,修改模版不会影响已创建的索引。
- 可以设定多个索引模版,这些设置会被"merge"在一起
- 可以指定"order"的数值,控制"merging"的过程
所有索引在创建的时候 都会把setting设置成主分片和副本分片都是1 PUT _template/template_default { "index_patterns":["*"], "order" : 0, "version" : 1, "settings" : { "number_of_shards" : 1, "number_of_replicas": 1 } }
Index template的工作方式
- 当一个索引被新创建时
- 应用Elasticsearch 默认的setting和mappings
- 应用order 数值低的 Index Template 中设定
- 应用order 高的Index Template 中设定,之前的设定会被覆盖
- 应用创建索引时,用户所指定的setting和mappings,并覆盖之前 模版中的设定
什么是Dynamic Template
-
根据Elasticsearch 识别的数据类型,结合字段名称,来动态设定字段类型
- 所有的字符串类型都设定Keyword,或者关闭keyword字段
- is 开头的字段都设置成boolean
- long_ 开头的都设置成long类型
-
Dynamic Template 是定义在某个索引的mapping中
-
Template有一个名称
-
匹配规则是一个数组
-
为匹配都字段设置Mapping