Debugging Shard Allocation

Is there any way to ask Elasticsearch why it allocated a shard to a specific node?

I've got a couple of different types of indexes in ES (some with small numbers of documents, others with millions more), and after rebooting various nodes to apply updates and, I've got an imbalanced cluster (all the million+ shards are allocated to one node).
Nothing obvious in the cluster or index settings is standing out as to why it's not allocating to the others. If ES can tell me "Index A, Shard B cannot be allocated to Node X because of [y,z]" then that'd be great.

then you will need to read into the code, first the interface

and then the concrete class, e.g.

and based on what concrete class, you see the logic maybe here



You can try doing for one shard and use ?explain to see what ES tells u. This is obviously not solving the initial ask, but can help us get some data from ES if indeed it can't allocate to other nodes.

Elasticsearch's allocation weights all shards the same. See the pull request below for some of the reasoning as to why. At some point in the future it'll have more, better ways of tuning this stuff, but for now your best bet is setting index.routing.allocation.total_shards_per_node on the big indexes.

1 Like

thanks @nik9000
To ensure even allocation of primaries to all nodes, we are setting a bit higher-number to below setting -


This was done to overcome issue where one of our 5 data nodes had all primary shards of all indices. We used guess and trial number, do we see any side-effect of messing up with this number :)?

Ah, nice. Thanks for that.