# 按顺序执行即可
# 删除老的 template
DELETE _template/process_log_templat
# 创建新的lifecycle
PUT _ilm/policy/process-log-lifecycle
{
"policy": {
"phases": {
"hot": {
"min_age": "0ms",
"actions": {
"rollover": {
"max_age": "30d",
"max_size": "20gb"
},
"set_priority": {
"priority": 100
}
}
},
"delete": {
"min_age": "90d",
"actions": {
"delete": {}
}
}
}
}
}
# 创建新的 template
PUT _template/process-log-template
{
"index_patterns": ["process-log-*"],
"settings": {
"number_of_shards": 2,
"index.lifecycle.name": "process-log-lifecycle",
"index.lifecycle.rollover_alias": "process-log",
"index" : {
"sort.field" : "requestTime",
"sort.order" : "desc"
}
},
"mappings": {
"properties":{
"consumeTime": {
"type": "long"
},
"insertTime": {
"type": "long"
},
"ip": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"method": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"params": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"requestTime": {
"type": "long"
},
"requestUri": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"responseTime": {
"type": "long"
},
"result": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"serverName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"status": {
"type": "long"
},
"userAgent": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
# 创建初始化索引
PUT process-log-000001
// 指定写索引
POST /_aliases
{
"actions" : [
{ "add" : { "index" : "process-log-202004", "alias" : "process-log","is_write_index" : false } },
{ "add" : { "index" : "process-log-202005", "alias" : "process-log","is_write_index" : false } },
{ "add" : { "index" : "process-log-000001", "alias" : "process-log","is_write_index" : true} }
]
}