ElasticSearch之Clone index API
1.ElasticSearch之安装2.ElasticSearch之查看集群的参数3.ElasticSearch之健康状态4.ElasticSearch的日志配置5.ElasticSearch之cat aliases API6.ElasticSearch之Health API7.ElasticSearch之Nodes info API8.ElasticSearch之系统关键配置9.ElasticSearch之cat allocation API10.ElasticSearch之cat anomaly detectors API11.ElasticSearch之cat component templates API12.ElasticSearch之配置13.ElasticSearch之cat count API14.ElasticSearch之cat data frame analytics API15.ElasticSearch之禁用交换分区16.ElasticSearch之虚拟内存17.ElasticSearch之文件描述符的数量18.ElasticSearch之线程的数量19.ElasticSearch之cat datafeeds API20.ElasticSearch之cat fielddata API21.ElasticSearch之cat health API22.ElasticSearch之cat indices API23.ElasticSearch之cat master API24.ElasticSearch之cat nodeattrs API25.ElasticSearch之线程池26.ElasticSearch之cat nodes API27.ElasticSearch之cat pending tasks API28.ElasticSearch之cat plugins API29.ElasticSearch之cat recovery API30.ElasticSearch之cat repositories API31.ElasticSearch之cat segments API32.ElasticSearch之cat shards API33.ElasticSearch之cat task management API34.ElasticSearch之cat templates API35.ElasticSearch之cat thread pool API36.ElasticSearch之Search settings37.ElasticSearch之cat trained model API38.ElasticSearch之cat transforms API39.ElasticSearch之Merge40.ElasticSearch之Force merge API41.ElasticSearch之Task management API42.ElasticSearch之Slow Log43.ElasticSearch之Analyze index disk usage API44.ElasticSearch之Clear cache API45.ElasticSearch之Create index API
46.ElasticSearch之Clone index API
47.ElasticSearch之Close index API48.ElasticSearch之Open index API49.ElasticSearch之Delete index API50.ElasticSearch之Exists API51.ElasticSearch之Get index API52.ElasticSearch之Get index settings API53.ElasticSearch之Index stats API54.ElasticSearch之Refresh API55.ElasticSearch之Shard request cache settings56.ElasticSearch之Node query cache settings57.ElasticSearch之Index modules58.ElasticSearch之集群中的节点59.ElasticSearch之网络配置使用已有的索引,复制得到一个索引。
关闭testindex_001
的写入操作,命令样例如下:
curl -X PUT "https://localhost:9200/testindex_001/_settings?pretty" -H 'Content-Type: application/json' -d' { "settings": { "index.blocks.write": true } } ' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
通过复制testindex_001
来创建新的index
,命令样例如下:
curl -X POST "https://localhost:9200/testindex_001/_clone/cloned-testindex_001?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{ "acknowledged" : true }
或者使用PUT
方法,命令样例如下:
curl -X PUT "https://localhost:9200/testindex_001/_clone/cloned-testindex_002?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{ "acknowledged" : true, "shards_acknowledged" : true, "index" : "cloned-testindex_002" }
假如复制前没有关闭写入,复制操作将失败,提示信息,样例如下:
{ "error" : { "root_cause" : [ { "type" : "illegal_state_exception", "reason" : "index testindex_001 must be read-only to resize index. use \"index.blocks.write=true\"" } ], "type" : "illegal_state_exception", "reason" : "index testindex_001 must be read-only to resize index. use \"index.blocks.write=true\"" }, "status" : 500 }
恢复testindex_001
的写入操作,命令样例如下:
curl -X PUT "https://localhost:9200/testindex_001/_settings?pretty" -H 'Content-Type: application/json' -d' { "settings": { "index.blocks.write": false } } ' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{ "acknowledged" : true }
实现原理
复制的操作过程:
- 依据源索引的参数和数据,使用目标索引的名称,创建一个新的索引对象。
- 将源索引相关的
segment
的对象和文件,关联至目标索引。- 假如节点的运行平台的文件系统支持POSIX语义中的硬链接,则使用硬链接方式。
- 假如节点的运行平台的文件系统不支持POSIX语义中的硬链接,则使用复制方式,相对要耗时,同时占用存储空间。
- 更新目标索引的状态,类似关闭后重新打开的索引。
约束项:
- 目标索引的名称需要符合命名规范。
- 目标索引不存在存在,否则复制操作将失败。
- 目标索引和源索引,主分片的数量需要一致。
- 参与复制操作的节点,需要有充足的存储空间来容纳新的索引的分片和副本。
方法参数
参考Create index API。
方法的请求消息体
参考Create index API。
方法的响应消息体
参考Create index API。
相关资料
本文来自博客园,作者:jackieathome,转载请注明原文链接:https://www.cnblogs.com/jackieathome/p/17871685.html
合集:
ElasticSearch
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南