The cluster.routing.allocation.require
setting in Elasticsearch is used to control cluster-level shard allocation based on custom node attributes. It allows you to specify requirements that must be met for a shard to be allocated to a particular node.
- Default value: Not set (no requirements)
- Possible values: Any custom node attribute key-value pair
- Recommendations: Use sparingly and in conjunction with other allocation settings for fine-grained control over shard placement
This setting is part of the shard allocation filtering mechanism in Elasticsearch. It enables you to define rules that require specific node attributes for shard allocation. When set, Elasticsearch will only allocate shards to nodes that have the specified attributes matching the defined values.
Example
To set a requirement that shards should only be allocated to nodes with a specific rack attribute:
PUT _cluster/settings
{
"persistent": {
"cluster.routing.allocation.require.rack": "rack1"
}
}
This change would cause Elasticsearch to only allocate shards to nodes that have the rack
attribute set to rack1
. You might want to do this to ensure data redundancy across physical racks in a data center.
Common Issues or Misuses
- Over-constraining shard allocation, leading to unallocated shards
- Forgetting to set the required attributes on nodes, resulting in allocation failures
- Using conflicting allocation rules that prevent proper shard distribution
Do's and Don'ts
Do's:
- Use in combination with other allocation settings for balanced distribution
- Regularly review and update allocation rules as your cluster grows or changes
- Document your allocation strategy for easier maintenance
Don'ts:
- Don't set overly restrictive requirements that could prevent shard allocation
- Avoid frequently changing allocation rules, as it can cause unnecessary shard migrations
- Don't rely solely on this setting for critical data placement; use multiple strategies
Frequently Asked Questions
Q: How does cluster.routing.allocation.require differ from cluster.routing.allocation.include?
A: While require
mandates that nodes must have the specified attributes to receive shards, include
allows allocation to nodes with matching attributes but doesn't exclude nodes without them.
Q: Can I use multiple attributes in the require setting?
A: Yes, you can specify multiple attributes. All specified attributes must be matched for a node to be eligible for shard allocation.
Q: What happens if no nodes match the require attributes?
A: If no nodes match the required attributes, shards will remain unallocated until matching nodes become available or the requirements are changed.
Q: How can I remove a require setting?
A: You can remove a require setting by setting its value to null using the cluster settings API.
Q: Does this setting affect existing shard allocations?
A: Yes, changing this setting can trigger reallocation of existing shards to comply with the new requirements.