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"
}
浙公网安备 33010602011771号