The cluster.routing.allocation.type
setting in Elasticsearch controls the algorithm used for shard allocation across nodes in a cluster. It determines how Elasticsearch distributes shards among available nodes to balance the cluster and optimize performance.
- Default value:
balanced
(as of Elasticsearch 7.x) - Possible values:
balanced
,even_shard
,disk_aware
- Recommendations: The default
balanced
setting is suitable for most use cases. However, for specific scenarios, you might consider changing it based on your cluster's needs and hardware configuration.
Example
To change the allocation type using the cluster settings API:
PUT _cluster/settings
{
"persistent": {
"cluster.routing.allocation.type": "even_shard"
}
}
You might want to change this setting if you have a specific requirement for shard distribution. For example, switching to even_shard
ensures that each node has an equal number of shards, which can be beneficial in certain high-performance scenarios.
Common Issues and Misuses
- Changing this setting without understanding its implications can lead to suboptimal shard distribution.
- Using
disk_aware
on clusters with heterogeneous hardware might cause unexpected allocation behavior.
Do's and Don'ts
- Do test changes in a non-production environment before applying them to your live cluster.
- Do monitor cluster performance and shard distribution after changing this setting.
- Don't change this setting frequently, as it can cause unnecessary shard relocations.
- Don't use
even_shard
if you have nodes with significantly different capacities.
Frequently Asked Questions
Q: What's the difference between balanced
and even_shard
allocation types?
A: balanced
considers various factors like disk usage and shard count for allocation, while even_shard
focuses solely on distributing an equal number of shards across nodes.
Q: When should I use the disk_aware
allocation type?
A: disk_aware
is useful in clusters with nodes having different disk capacities, as it prioritizes allocating shards to nodes with more available disk space.
Q: How does changing the allocation type affect existing shard allocations?
A: Changing the allocation type may trigger shard relocations to comply with the new allocation strategy, which can temporarily impact cluster performance.
Q: Can I set different allocation types for different indices?
A: No, cluster.routing.allocation.type
is a cluster-wide setting and applies to all indices.
Q: How often should I review and potentially change the allocation type?
A: It's best to set an appropriate allocation type during cluster setup and only change it if there's a significant change in your cluster's hardware or workload patterns.