Elasticsearch index.routing.allocation.require Setting

Pulse - Elasticsearch Operations Done Right

On this page

Example Common Issues or Misuses Do's and Don'ts Frequently Asked Questions

The index.routing.allocation.require setting in Elasticsearch is used to control index-level shard allocation based on node attributes. It allows you to specify conditions that must be met for a shard to be allocated to a particular node.

  • Default value: Not set
  • Possible values: Any valid node attribute key-value pair
  • Recommendations: Use this setting judiciously to ensure proper shard distribution and avoid allocation issues

This setting is part of the index-level settings and can be applied to specific indices. It works by requiring that nodes have certain attributes matching the specified values for shards to be allocated to them. This can be useful for controlling data placement based on hardware characteristics, geographical location, or other custom attributes.

Example

To set the index.routing.allocation.require setting using the cluster settings API:

PUT /my_index/_settings
{
  "index.routing.allocation.require.zone": "zone1"
}

In this example, we're setting the requirement that shards of the my_index index should only be allocated to nodes with the attribute zone set to zone1. This could be useful in scenarios where you want to ensure data is stored in a specific data center or geographical region.

The effect of this change would be that Elasticsearch will only allocate shards of my_index to nodes that have the zone attribute set to zone1. If no such nodes are available, the shards may remain unassigned.

Common Issues or Misuses

  • Over-constraining shard allocation, leading to unassigned shards
  • Conflicting allocation rules between different settings
  • Not considering the impact on cluster balance and performance

Do's and Don'ts

  • Do use this setting to implement logical separation of data
  • Do consider the overall cluster health and shard distribution when applying this setting
  • Don't set overly restrictive requirements that could prevent proper shard allocation
  • Don't forget to monitor the cluster for unassigned shards after applying this setting

Frequently Asked Questions

Q: Can I use multiple attributes in the index.routing.allocation.require setting?
A: Yes, you can specify multiple attributes. All specified attributes must be matched for a shard to be allocated to a node.

Q: How does this setting interact with other allocation settings?
A: This setting is combined with other allocation settings like index.routing.allocation.include and index.routing.allocation.exclude. All conditions from these settings must be satisfied for shard allocation.

Q: Can I change this setting on a live index?
A: Yes, you can change this setting on a live index. Elasticsearch will attempt to relocate shards to comply with the new setting, which may cause some reallocation of data.

Q: What happens if no nodes match the required attributes?
A: If no nodes match the required attributes, the shards will remain unassigned until matching nodes become available or the setting is changed.

Q: How can I view the current allocation requirements for an index?
A: You can use the Get Index Settings API to view the current settings for an index, including the allocation requirements.

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.