建一个索引的步骤
1:先创建轮滚策略
2:创建模板
3:创建索引
创建轮滚策略
PUT _ilm/policy/this_is_an_index_policy { "policy" : { "phases" : { "hot" : { "min_age" : "0ms", "actions" : { "rollover" : { "max_size" : "100gb", "max_age" : "7d" } } }, "delete" : { "min_age" : "7300d", "actions" : { "delete" : { } } } } } }
创建索引模板
PUT /_template/this-is-an-index-template { "order" : 0, "index_patterns" : [ "this-is-an-index-*" ], "settings" : { "index" : { "lifecycle" : { "name" : "this_is_an_index_policy", # 这里要指向刚才创建的轮滚策略 "rollover_alias" : "this-is-an-index" # 这个是轮滚后的索引的别名 }, "search" : { "slowlog" : { "level" : "info", "threshold" : { "fetch" : { "warn" : "800ms", "info" : "300ms" }, "query" : { "warn" : "800ms", "info" : "300ms" } } } }, "refresh_interval" : "60s", "number_of_shards" : "6", "number_of_replicas" : "1" } }, "mappings" : { "dynamic" : "false", "properties" : { "os_info" : { "type" : "keyword" }, "app" : { "type" : "keyword" }, "content" : { "type" : "text", "fields" : { "keyword" : { "ignore_above" : 256, "type" : "keyword" } } }, "province" : { "type" : "keyword" } } }, "aliases" : {} }
根据模板创建索引
PUT /this-is-an-index-000001
{
"aliases": {
"this-is-an-index": {
"is_write_index" : true
}
}
}
创建索引后,如果要观察轮滚效果,可以手动滚动
POST /this-is-an-index/_rollover