sjsj15
sjsj15

Reputation: 805

ElasticSearch - Restrict primary and replica shards count on nodes

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.

Upvotes: 1

Views: 1171

Answers (2)

Amit
Amit

Reputation: 32376

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
{
 "persistent":{
    "cluster.routing.allocation.enable": "all"
    }
}

Command to disable rebalance

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

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.

Upvotes: 2

hamid bayat
hamid bayat

Reputation: 2179

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.

Upvotes: 0

Related Questions