diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java index e49ab2e6e43..3d429fa5dad 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java @@ -52,9 +52,9 @@ public class SameShardAllocationDecider extends AllocationDecider { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - for (MutableShardRouting nodeShard : node) { - // we do not allow for two shards of the same shard id to exists on the same node - if (nodeShard.shardId().equals(shardRouting.shardId())) { + Iterable assignedShards = allocation.routingNodes().assignedShards(shardRouting); + for (MutableShardRouting assignedShard : assignedShards) { + if (node.nodeId().equals(assignedShard.currentNodeId())) { return Decision.NO; } } @@ -68,8 +68,8 @@ public class SameShardAllocationDecider extends AllocationDecider { if (!checkNode.node().address().sameHost(node.node().address())) { continue; } - for (MutableShardRouting nodeShard : checkNode) { - if (nodeShard.shardId().equals(shardRouting.shardId())) { + for (MutableShardRouting assignedShard : assignedShards) { + if (checkNode.nodeId().equals(assignedShard.currentNodeId())) { return Decision.NO; } }