一、题目
给索引my-index-000001,创建别名my-index,并设置rollover,满足以下三个条件的
- The index was created 7 or more days ago.
- The index contains 5 or more documents.
- The index’s largest primary shard is 1GB or larger.
二、思考
这里有几个注意点
- rollover 需要基于别名创建,所以要先创建别名;
- 别名要求是可以支持数据写入;
三、解题
Step 1、创建索引并指定别名和可写入
PUT /my-index-000001
{
"aliases": {
"my-index": {
"is_write_index": true
}
}
}
Step 2、创建rollover
注意:conditions里配置的条件,条件之间是或的关系,也就是说满足任意一条就会被执行rollover
POST my-alias/_rollover
{
"conditions": {
"max_age": "7d",
"max_docs": 5,
"max_primary_shard_size": "1gb"
}
}
通过执行结果可以看出,如果rollover生效后的新索引名称是 my-index-000002
Step 3、通过别名导入5条数据
注意:my-index是别名,而非索引名称
POST my-index/_bulk
{"create":{"_id":1}}
{"a":"key","b":"mom","c":"mom","d":"mom","e":"mom"}
{"create":{"_id":2}}
{"a":"key","b":"cake mix","c":"mom","d":"tom","e":"1"}
{"create":{"_id":3}}
{"a":"key","b":"mom","c":"cake mix","d":"kate","e":"2"}
{"create":{"_id":4}}
{"a":"cake mix","b":"mom","c":"mom","d":"alex","e":"3"}
{"create":{"_id":5}}
{"a":"cake m","b":"mom","c":"mom","d":"alex","e":"3"}
Step 4、通过别名再导入第6条数据
indices.lifecycle.poll_interval:代表索引生命周期管理检查符合 policy 策略标准的索引的频率,是检查是否满足 rollover 的周期频率值,默认 10 分钟。为了加快验证看到效果,可以设置的短一点
PUT cluster/_settings
{
"persistent": {
"indices.lifecycle.poll_interval": "ls"
}
}
更新完集群索引刷新频率后,插入第6条数据进行验证是否可以写入到新的索引
POST my-index/_bulk
{"create":{"_id":6}}
{"a":"k555","b":"mom","c":"mom","d":"mom","e":"mom"}
从执行结果上可以看到已经切换到新的索引 my-index-000002
四、总结
- rollover 需要基于别名创建,所以要先创建别名,别名要求是可以支持数据写入
- rollover 配置的条件,条件间都是或的逻辑
- 数据的写入也要基于别名
- 通过修改集群索引周期刷新频率可以快速验证 indices.lifecycle.poll_interval
参考资料
送一波福利:
福利一
有需要内推JD的同学,可以私信或留言,我帮您内推,流程快!!!
有需要内推JD的同学,可以私信或留言,我帮您内推,流程快!!!
有需要内推JD的同学,可以私信或留言,我帮您内推,流程快!!!
福利二
福利三