index template
作用
Index template 在创建新 index 时可以自动应用的 settings 和 mappings。 Elasticsearch 根据与 index 名称匹配的 index 模式将模板应用于新索引。
Index template 仅在 index 创建期间应用。 对 index template 的更改不会影响现有索引。 create index API 请求中指定的设置和映射会覆盖索引模板中指定的任何设置或映射。
定义一个template
PUT /_template/<index-template>
例如
PUT _template/logs_template
{
"index_patterns": "logs-*",
"order": 1,
"settings": {
"number_of_shards": 4,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
}
}
}
}
定义了一个叫做 logs_template 的 index template。它的 index_patterns 定义为 “logs-*”,说明,任何以 “logs-” 为开头 index 将具有在该 template 里定义的 settings 及 mappings 属性。“order” :如果索引与多个模板匹配&