建一個索引的步驟
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" : { } } } } } }
獲取模板
GET _ilm/policy/experience_manager_platform_policy
創建索引模板
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
修改mapping后數據操作:
update by query
POST /my-index/_update_by_query?conflicts=proceed { "script": { "source": "ctx._source.new_field = ctx._source.old_field", "lang": "painless" }, "query": { "exists": { "field": "old_field" } } }
reindex
POST _reindex { "source": { "index": "index-v1", "query": { "range": { "created_at": { "gte": <一個時間點> } } } }, "dest": { "index": "index-v2" } }
浙公網安備 33010602011771號