Home > database >  ElasticSearch - Restrict primary and replica shards count on nodes
ElasticSearch - Restrict primary and replica shards count on nodes

Time:10-28

I have ElasticSearch 7.16.2 cluster running with three nodes (2 master , 1 Voting node). An index has two primary shards and two replicas, and on restarting a node, both primary shards move to single node. How to restrict index in a nodes to have one primary shard and one replica each.

CodePudding user response:

You can use the index level shard allocation settings to achieve that, it might be not that straight forward and it's a bit complex setting and can cause further unbalance when you have a changing nodes and indices in the cluster.

In order to avoid the issue which happens on the node restart, you must disable the shard allocation and shard rebalance before starting your nodes in Elasticsearch cluster.

Command to disable allocation

PUT /_cluster/settings
{
    "cluster": {
        "routing.allocation.enable": false
    }
}

Command to disable rebalance

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

Apart from that, you can use the reroute API to manually move the shards to a node in Elasticsearch to fix your current shard allocation.

CodePudding user response:

the config is index.routing.allocation.total_shards_per_node. but you have a problem. first of all I assume you have three data node. (if you don't have, increase the data nodes.).

the problem is you have 4 primary and replica shard in total and one node must assign two shards to itself. so you could not the set index.routing.allocation.total_shards_per_node to 1. at least it must be 2 and your problem not solved.

the config is dynamic: https://www.elastic.co/guide/en/elasticsearch/reference/master/increase-shard-limit.html

also you could set cluster.routing.allocation.total_shards_per_node config for cluster.

  • Related