Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading