创建索引模板
索引模板就是创建好一个索引参数设置(settings)和映射(mapping)的模板,在创建新索引的时候指定模板名称就可以使用模板定义好的参数设置和映射。例如:
PUT _template/mytemplate
{
"index_patterns": "mylog*",
"settings": {
"number_of_shards": 5,
"number_of_replicas": 2
},
"mappings": {
"type": {
"properties": {
"name": {
"type": "keyword"
},
"age": {
"type": "keyword"
}
}
}
}
}
模板名称是mytemplate,定义好模板可以使用mylog*来适配,分片数量5,副本数量2,默认文档类型是type
删除模板
DELETE _template/mytemplate
获取模板
得到所有的模板:GET _template/
使用通配符或逗号分割:GET _template/my*
使用模板
当在添加数据时,指定索引名匹配index_patterns时,ES就会自动为数据新建一个索引。
本文介绍如何在Elasticsearch中创建索引模板,包括设置分片数量、副本数量和映射字段类型,以及如何删除和获取模板,当添加数据时如何自动应用模板创建索引。
1635

被折叠的 条评论
为什么被折叠?



