目前我們使用的elastic版本為2.3.5
當前版本沒有直接的curl操作可以更改索引的名稱,索引的副本數。
有直接更改索引副本數的api。
curl -XPUT "192.168.1.1:9200/test001/_settings" -d '{
"index" : {
"number_of_replicas" : 2
}
}'
但是,我們可以通過elastic的快照功能來實現以上兩種操作。
1.索引重命名
1.0 准備工作:停止對目標索引做插入數據操作
1.1 對需要重命名的索引做快照
curl -XPUT "192.168.1.1:9200/_snapshot/my_backup/test001_20171212?wait_for_completion=true&pretty=true" -d '{ "indices": "test001", "ignore_unavailable": "true", "include_global_state": false, "include_aliases": false, "partial": "false" }'
1.2 通過恢復快照重命名索引
curl -XPOST "192.168.1.1:9200/_snapshot/my_backup/test001_20171212/_restore?wait_for_completion=true&pretty=true" -d '{ "indices": "test001", "ignore_unavailable": "true", "include_global_state": false, "include_aliases": false, "partial": "false", "rename_pattern": "test001", "rename_replacement": "test001_old" }'
2.索引副本數修改
2.0 同1.0
2.1 同1.1
2.2 通過恢復快照更改索引的副本數【以下代碼更改索引副本數為1,相當於共兩份數據】
curl -XPOST "192.168.1.1:9200/_snapshot/my_backup/test001_20171212/_restore?wait_for_completion=true&pretty=true" -d '{ "indices": "test001", "index_settings": { "index.number_of_replicas": 1 }, "ignore_unavailable": "true", "include_global_state": false, "include_aliases": false, "partial": "false", "rename_pattern": "test001", "rename_replacement": "test001" }'