您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch索引模板
发布时间:2021-09-04 15:21:27编辑:雪饮阅读()
在elasticSearch中前面有了解过索引创建过程中可以附带定义映射、设置、别名的。当然这些也可以单独为某个索引定义。
那么这次来了解下索引模板,这里是单独建立索引模板,通过索引模板去匹配到某个索引,那么假如该模板里定义了索引的一些默认配置,那么该模板建立之后若再建立一个索引,该索引名称正符合刚才建立的这个索引模板所匹配到的索引名称范围之内,则新建的这个索引就会继承刚才建立的这个索引模板的默认配置。
比如建立一个索引模板
请求正文:
{
"index_patterns" : ["te*"],
"priority" : 1,
"template": {
"settings" : {
"number_of_shards" : 2
}
}
}
响应正文:
{
"acknowledged": true
}
该模板匹配了索引名以“te”开头的索引。并配置了settings中number_of_shards为2
那么接下来我们就建立以”te”开头的索引并查看这个新建立的以”te”开头的索引的设置信息
请求正文:none
响应正文:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "test"
}
这样就建立了te开头的索引
然后查看这个te开头的索引的设置信息
请求正文:none
响应正文:
{
"test": {
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "2",
"provided_name": "test",
"creation_date": "1630739019791",
"number_of_replicas": "1",
"uuid": "ncLmBovtTFKCO9mrSCbG5Q",
"version": {
"created": "7140099"
}
}
}
}
}
可以看到number_of_shards果然是2.
那么接下来建立一个非te开头的索引并查看其设置信息
请求正文:none
响应正文:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "xy"
}
然后查看这个非te开头的索引的设置信息
请求正文:none
响应正文:
{
"xy": {
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "xy",
"creation_date": "1630739149913",
"number_of_replicas": "1",
"uuid": "Ugh0E8ZTQIaqdKFytMDQng",
"version": {
"created": "7140099"
}
}
}
}
}
这里number_of_shards为1,就是因为它不是以te开头的索引,所以它不用遵循继承上面新建立那个template_1索引模板中的设置信息。
关键字词:elasticSearch,索引模板
上一篇:elasticSearch分析