@Override
protected ShardIterator shards(ClusterState clusterState, InternalRequest request) throws ElasticsearchException {
if (request.request().shardId() != -1) {
return clusterState.routingTable().index(request.concreteIndex()).shard(request.request().shardId()).primaryShardIt();
}
ShardIterator shardIterator = clusterService.operationRouting()
.indexShards(clusterState, request.concreteIndex(), request.request().type(), request.request().id(), request.request().routing());
ShardRouting shard;
while ((shard = shardIterator.nextOrNull()) != null) {
if (shard.primary()) {
return new PlainShardIterator(shardIterator.shardId(), ImmutableList.of(shard));
}
}
return new PlainShardIterator(shardIterator.shardId(), ImmutableList.<ShardRouting>of());
}