Index template 定义在创建新 index 时可以自动应用的 settings 和 mappings。 Elasticsearch 根据与 index 名称匹配的 index 模式将模板应用于新索引。这个对于我们想创建的一系列的 Index 具有同样的 settings 及 mappings。比如我们希望每一天/月的日志的index都具有同样的设置。
- 创建一个模板
PUT _index_template/ellis
{
"index_patterns": ["ellis*"],
"template":
{
"settings":
{
"number_of_shards": 1
},
"mappings":{
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
},
"aliases": {
"mydata": { }
}
},
"priority":20
}
priority可选配置,创建新索引时确定索引模板优先级(针对多个模板匹配)。选择具有最高优先级的索引模板。如果未指定优先级,则将模板视为优先级为0(最低优先级)
aliases 是要设置的别名
- 查询index 是否存在
HEAD _index_template/ellis
- 删除模板
DELETE _index_template/ellis
参考
https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html