ElasticSearch之Clone index API

使用已有的索引,复制得到一个索引。

关闭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

相关资料

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小南家的青蛙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值