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 4ff1e660698a6..84ef35e017d66 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -482,9 +482,6 @@ void executeRequest( OpenPointInTimeRequest pitReq = new OpenPointInTimeRequest(searchRequest.indices()).indicesOptions( searchRequest.indicesOptions() ).preference(searchRequest.preference()).routing(searchRequest.routing()).keepAlive(TimeValue.ONE_MINUTE); - - // The can match phase can reorder shards, so we disable it to ensure the stable ordering - searchRequest.setPreFilterShardSize(Integer.MAX_VALUE); nodeClient.execute(TransportOpenPointInTimeAction.TYPE, pitReq, new ActionListener<>() { @Override public void onResponse(OpenPointInTimeResponse resp) { @@ -504,6 +501,11 @@ public void onFailure(Exception e) { }); return; } + if (retriever.isCompound()) { + // The can match phase can reorder shards, so we disable it to ensure the stable ordering + // when running multiple requests within the same pit. + searchRequest.setPreFilterShardSize(Integer.MAX_VALUE); + } Rewriteable.rewriteAndFetch( searchRequest, searchService.getRewriteContext(timeProvider::absoluteStartMillis, resolvedIndices, searchRequest.pointInTimeBuilder()),