Elasticsearch Template
前言
当集群上的索引越来越多时,可以使用 Index Templates 帮助你设定 Mappings 和 Settings。并按照一定的规则,自动匹配到新创建的索引之上。
1. Index Template
集群上如果保存的是日志,为了更好的管理数据,需要每天都创建一个索引。创建索引需要创建 Settings 和 Mappings,那么可以使用 Index Template 来创建。
一、什么是 Index Template
帮助设定 Mappings 和 Settings,并按照一定的规则,自动匹配到新创建的索引之上。
- 模版仅在一个索引被新创建时,才会产生作用。修改模版不会影响已经创建的索引。
- 可以设定多个索引模板,这些设置会被 “merge” 在一起
- 可以指定 “order” 的数值,控制先合并哪些模板
当一个索引被新创建时:
- 第一应用 Elasticsearch 默认的 settings 和 mappings。
- 第二应用 order 数值低的 index template。
- 第三应用 order 高的 index template,之前的设定会被覆盖。
- 第四应用创建索引时,用户指定的 settings 和 mappings,会覆盖之前模版中的设定。
PUT _template/template_default
{
"index_patterns": ["*"],
&#