diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index 46207b94c3af4..51ee8b045bfee 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -345,8 +345,13 @@ private void executeSearch(SearchTask task, SearchTimeProvider timeProvider, Sea * We try to set a default of max concurrent shard requests based on the node count but upper-bound it by 256 by default to keep * it sane. A single search request that fans out to lots of shards should not hit a cluster too hard while 256 is already a * lot. + * Yet we are still trying to guarantee some concurrency ie. if you have an index size of N shards and you are searching a + * single index on a single node we still search it concurrently. */ - searchRequest.setMaxConcurrentShardRequests(Math.min(256, nodeCount)); + final int numShards = shardIterators.size(); + final int numIndices = remoteClusterIndices.size() + concreteIndices.length; + assert numShards >= numIndices : "found schroedingers index numShards: " + numShards + " vs. numIndices: " + numIndices; + searchRequest.setMaxConcurrentShardRequests(Math.min(256, nodeCount * (numShards / numIndices))); } boolean preFilterSearchShards = shouldPreFilterSearchShards(searchRequest, shardIterators); searchAsyncAction(task, searchRequest, shardIterators, timeProvider, connectionLookup, clusterState.version(),