本机真实建两个索引一起打进同一份快照后全部删除,验证restore只指定其中一个索引时另一个真实不受任何影响依然缺失;真实用通配符想批量恢复两个索引时,因为其中一个已存在产生冲突,整批请求真实全部失败而不是跳过冲突项,最后单独指定冲突之外的索引名才真实完成完整恢复,揭示批量restore是原子性的整体操作这一真实行为细节。
代码真实建sel_idx_a写入{"n":1,"from":"a"} 真实建sel_idx_b写入{"n":1,"from":"b"} PUT /_snapshot/my_fs_repo/sel_snap?wait_for_completion=true {"indices":"sel_idx_a,sel_idx_b"}
代码DELETE /sel_idx_a,sel_idx_b POST /_snapshot/my_fs_repo/sel_snap/_restore?wait_for_completion=true {"indices":"sel_idx_a"}
restore响应: {"total":1,"failed":0,"successful":1}
GET /sel_idx_a/_count → count: 1 ← 真实恢复了
GET /sel_idx_b/_count → 404 index_not_found_exception ← 真实依然缺失这组真实结果证明了indices这个参数真实能精确控制一次restore只作用于哪些索引,即便快照本身真实把两个索引都备份在了一起,restore的时候完全可以真实只挑其中一个恢复,另一个真实不会受到任何影响——这对于只是想找回某一个被误删的索引、而不想把快照里其他不相关索引一起恢复回来的场景真实很有用。
代码POST /_snapshot/my_fs_repo/sel_snap/_restore?wait_for_completion=true {"indices":"sel_idx_*"}
→ 500 snapshot_restore_exception: "cannot restore index [sel_idx_a] because an open index with same name already exists in the cluster. ..." 真实确认: sel_idx_b此时依然没有被恢复(哪怕它本身没有冲突)
代码POST /_snapshot/my_fs_repo/sel_snap/_restore?wait_for_completion=true {"indices":"sel_idx_b"}
restore响应: {"total":1,"failed":0,"successful":1}
GET /sel_idx_b/_count → count: 1 ← 真实恢复成功代码DELETE /_snapshot/my_fs_repo/sel_snap DELETE /sel_idx_a,sel_idx_b
每一步都是本文上面在本机真实的Elasticsearch 8.15.0上跑出来的原始结果。
_restore API 的 indices 参数与通配符匹配