Elasticsearch cluster.routing.allocation.same_shard.host Setting

Pulse - Elasticsearch Operations Done Right

On this page

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

The cluster.routing.allocation.same_shard.host setting in Elasticsearch controls whether multiple copies of the same shard can be allocated to different nodes on the same host. This setting is crucial for maintaining data redundancy and availability in multi-node Elasticsearch clusters.

Description

  • Default value: false
  • Possible values: true or false
  • Recommendation: Keep the default value (false) for most production environments

When set to false (default), Elasticsearch will not allocate multiple copies of the same shard to nodes that share the same host. This behavior helps ensure that if a physical machine fails, you don't lose multiple copies of the same shard.

Setting this to true allows Elasticsearch to allocate replica shards on the same host as the primary shard. This configuration might be useful in development or testing environments but is generally not recommended for production use.

Example

To change this setting using the cluster settings API:

PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.same_shard.host": true
  }
}

You might want to change this setting to true if you're running a development environment with limited resources and want to simulate a multi-node cluster on a single machine. However, be aware that this reduces the fault tolerance of your cluster.

Common Issues and Misuses

  • Setting this to true in production environments can lead to data loss if a physical host fails
  • Misunderstanding the implications of this setting can result in unexpected shard allocation behavior
  • Forgetting to reset this value when moving from a development to a production environment

Do's and Don'ts

  • Do keep this setting as false in production environments
  • Do use this setting to simulate multi-node setups on a single machine for development or testing
  • Don't enable this in production unless you fully understand the implications and have a specific reason to do so
  • Don't forget to monitor shard allocation when changing this setting

Frequently Asked Questions

Q: How does this setting affect cluster resilience?
A: When set to false, it improves cluster resilience by ensuring that copies of the same shard are on different physical hosts, reducing the risk of data loss if a host fails.

Q: Can I use this setting to improve shard allocation speed?
A: While setting this to true might speed up initial shard allocation in some cases, it's not recommended as a performance optimization technique due to the increased risk of data loss.

Q: How does this setting interact with other allocation settings?
A: This setting works in conjunction with other allocation settings. For example, it's considered after cluster.routing.allocation.awareness settings are applied.

Q: Is this setting dynamic?
A: Yes, this setting can be changed dynamically using the cluster settings API without requiring a cluster restart.

Q: How can I verify the current value of this setting?
A: You can check the current value using the cluster settings API: GET _cluster/settings?include_defaults=true

Subscribe to the Pulse Newsletter

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