索引命名
业务索引: 业务+版本号
日志索引:业务+日期时间
索引别名
POST _aliases
{
"actions" : [
{
"add" : {
"index" : "test_index",
"alias" : "test_alias",
"is_write_index" : true
}
}
]
}
通过别名来滚动更新索引
先create一个新的索引
PUT test_index2
再将alias指向新的索引并移除旧的alias
POST _aliases
{
"actions": [
{
"remove": {
"index": "test_index2",
"alias": "test_alias"
}
},
{
"add": {
"index": "test_index",
"alias": "test_alias",
"is_write_index": true
}
}
]
}
创建方式
- 动态创建 - 直接put
- 静态创建 - 指定mapping
- 滚动创建
滚动索引命名要规范,符合自动增长模式,建议字母(必须小写字母)+6位数字
方式一
# 语法1
POST /<rollover-target>/_rollover/<target-index>
# 语法2
POST /<rollover-target>/_rollover/
# 案例
PUT /rolltest-rollover-index-000001
{
"aliases":{
"rolltest-rollover-index":{}
}
}
POST rolltest-rollover-index/_rollover
# 官方案例
PUT /logs-000001
{
"aliases": {
"logs_write": {}
}
}
POST /logs_write/_rollover
{
"conditions": {
"max_age": "7d",
"max_docs": 1000,
"max_size": "5gb"
}
}
## 响应
{
"acknowledged" : false,
"shards_acknowledged" : false,
"old_index" : "logs-000001",
"new_index" : "logs-000002",
"rolled_over" : false,
"dry_run" : false,
"conditions" : {
"[max_size: 5gb]" : false,
"[max_docs: 1000]" : false,
"[max_age: 7d]" : false
}
}