The cluster.routing.allocation.awareness.force
setting in Elasticsearch controls the behavior of shard allocation when using awareness attributes. It forces Elasticsearch to allocate the primary and replica shards of an index to different awareness values, even if it means some shards cannot be allocated to any node.
Description
- Default value: Empty map (
{}
) - Possible values: A map of index patterns to lists of awareness attribute values
- Recommendation: Use with caution, as it can prevent shard allocation if not enough awareness values are available
This setting is used in conjunction with cluster.routing.allocation.awareness.attributes
to enforce strict shard distribution across different awareness zones. When set, Elasticsearch will ensure that primary and replica shards are allocated to different awareness values for the specified indices, even if it means leaving some shards unassigned.
Example
To force shards of indices matching the pattern my-index-*
to be allocated across two awareness values "zone1" and "zone2":
PUT _cluster/settings
{
"persistent": {
"cluster.routing.allocation.awareness.force": {
"my-index-*": "zone1,zone2"
}
}
}
This change would ensure that for any index matching my-index-*
, primary and replica shards are always allocated to different zones. If either zone becomes unavailable, some shards may remain unassigned rather than violating this rule.
Common Issues
- Unassigned shards due to insufficient awareness values
- Reduced cluster availability if an awareness zone becomes unavailable
- Overuse leading to suboptimal shard distribution in small clusters
Do's and Don'ts
Do's:
- Use when strict separation of shards across awareness attributes is critical
- Ensure enough nodes with different awareness values are available
- Monitor shard allocation closely when using this setting
Don'ts:
- Don't use in small clusters with limited awareness values
- Avoid applying to all indices unless absolutely necessary
- Don't combine with other allocation settings that may conflict
Frequently Asked Questions
Q: What happens if there aren't enough awareness values available for allocation?
A: If there aren't enough awareness values available to satisfy the force rules, some shards will remain unassigned to maintain the separation.
Q: Can I use this setting with a single-node cluster?
A: It's not recommended, as it requires multiple nodes with different awareness values to be effective.
Q: How does this setting interact with other shard allocation settings?
A: This setting takes precedence over most other allocation settings. It may conflict with or override other allocation rules.
Q: Can I change the awareness force settings dynamically?
A: Yes, you can update these settings dynamically using the cluster settings API without restarting nodes.
Q: What's the difference between awareness and forced awareness?
A: Regular awareness tries to spread shards across different attribute values but will allocate all shards if necessary. Forced awareness will leave shards unassigned rather than violate the awareness rules.