diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java index b1bc22d2287..abc75eb73ef 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java @@ -162,7 +162,7 @@ public class IndexShardRoutingTable implements Iterable { public ShardIterator preferLocalShardsIt(String nodeId) { ArrayList ordered = new ArrayList(this.shards.size()); // fill it in a randomized fashion - int index = counter.getAndIncrement(); + int index = Math.abs(counter.getAndIncrement()); for (int i = 0; i < this.shards.size(); i++) { int loc = (index + i) % this.shards.size(); ordered.add(this.shards.get(loc));