Possible to have Elasticsearch prefer same availability zone shard allocation?

Hi All,

I'm curious if anyone knows if the following scenario is possible within Elasticsearch.

Suppose I have a 6-node cluster spread across 3 availability zones (AZ) (2 nodes per AZ). I want to have some resiliency, but my use-case doesn't require a significant amount and focuses more on cost savings. In this case, I want to minimize the amount of cross-AZ traffic (cost) that would happen.

I'd like to be able to tell Elasticsearch that when it schedules an index/shards, to keep the primary and replica shard in the same AZ if possible, but don't allocate on the same node. If not possible, then try to allocate across AZs, but when possible again, to move the shards back to the same AZ.

I've looked at the following doc areas, but couldn't really find anything that would indicate this is possible:

I believe what you are asking for is indeed not possible but wanted to add a comment as well.

If you were able to do this you would end up with both primary and replica in the same AZ. This gives you protection and resiliency against node-level failures but you would lose part of your data if a full AZ fails. If node-level failure resiliency is sufficient or a viable tradeoff, why not simply deploy all nodes in a single AZ? You could still use reasoinably frequent snapshots to ensure you could restore the cluster with limited data loss if you lost the full AZ.

Interesting use case — unfortunately, Elasticsearch doesn’t support “prefer same AZ” for primaries and replicas out of the box. With allocation awareness, it actually tries to spread them across AZs for resilience.

If you want both shards in the same AZ, you’d need to avoid awareness and use index-level allocation filtering — but that gets manual fast.

Would be great if Elastic added soft preferences like this in the future.