elasticsearch索引分片手动迁移(Index-level shard allocation filtering)

介绍

  You can use shard allocation filters to control where Elasticsearch allocates shards of a particular index. These per-index filters are applied in conjunction with cluster-wide allocation filtering and allocation awareness.
  Shard allocation filters can be based on custom node attributes or the built-in _name, host_ip, publish_ip, _ip, and _host attributes. Index lifecycle management uses filters based on custom node attributes to determine how to reallocate shards when moving between phases.

 

Index-level shard allocation filtering用于索引级别的分片配置,指定分片可以分配到什么节点、ip、主机名。

测试实验

启动三个数据节点,创建索引配置为2个分片1个副本。

复制代码
PUT /hamlet
{
  "settings": {
    "index": {
      "number_of_shards": 2,
      "number_of_replicas": 1
    }
  }
}
复制代码

写入一些数据

复制代码
PUT hamlet/_bulk
{"index":{"_index":"hamlet-1","_id":0}}
{"line_number":"1","speaker":"BERNARDO","text_entry":"Whos there?"}
{"index":{"_index":"hamlet-1","_id":1}}
{"line_number":"2","speaker":"FRANCISCO","text_entry":"Nay, answer me: stand, and unfold yourself."}
{"index":{"_index":"hamlet-1","_id":2}}
{"line_number":"3","speaker":"BERNARDO","text_entry":"Long live the king!"}
{"index":{"_index":"hamlet-1","_id":3}}
{"line_number":"4","speaker":"FRANCISCO","text_entry":"Bernardo?"}
{"index":{"_index":"hamlet-1","_id":4}}
{"line_number":"5","speaker":"BERNARDO","text_entry":"He."}
复制代码

强制将所有主分片分配到节点0,副本分配到节点1。(下面步骤不一定可以完成,主副分片不能在同一节点,可能会无法正常rebalance,需要考虑原来分片的位置,调整分配的方式。)

复制代码
PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.rebalance.enable": "primaries"
  }
}

PUT hamlet/_settings
{
  "index.routing.allocation.include._name" : "node0"
}

PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.rebalance.enable": "replicas"
  }
}

PUT hamlet/_settings
{
  "index.routing.allocation.include._name" : "node1"
}
复制代码
posted @   哪都通临时工  阅读(647)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示