@@ -582,32 +582,35 @@ private void loadOrExecuteQueryPhase(final ShardSearchRequest request, final Sea
582582 }
583583
584584 public void executeQueryPhase (ShardSearchRequest request , SearchShardTask task , ActionListener <SearchPhaseResult > listener ) {
585- ActionListener <SearchPhaseResult > finalListener = maybeWrapListenerForStackTrace (listener , request .getChannelVersion (), threadPool );
586585 assert request .canReturnNullResponseIfMatchNoDocs () == false || request .numberOfShards () > 1
587586 : "empty responses require more than one shard" ;
588587 final IndexShard shard = getShard (request );
589- rewriteAndFetchShardRequest (shard , request , finalListener .delegateFailure ((l , orig ) -> {
590- // check if we can shortcut the query phase entirely.
591- if (orig .canReturnNullResponseIfMatchNoDocs ()) {
592- assert orig .scroll () == null ;
593- ShardSearchRequest clone = new ShardSearchRequest (orig );
594- CanMatchContext canMatchContext = new CanMatchContext (
595- clone ,
596- indicesService ::indexServiceSafe ,
597- this ::findReaderContext ,
598- defaultKeepAlive ,
599- maxKeepAlive
600- );
601- CanMatchShardResponse canMatchResp = canMatch (canMatchContext , false );
602- if (canMatchResp .canMatch () == false ) {
603- finalListener .onResponse (QuerySearchResult .nullInstance ());
604- return ;
588+ rewriteAndFetchShardRequest (
589+ shard ,
590+ request ,
591+ maybeWrapListenerForStackTrace (listener , request .getChannelVersion (), threadPool ).delegateFailure ((l , orig ) -> {
592+ // check if we can shortcut the query phase entirely.
593+ if (orig .canReturnNullResponseIfMatchNoDocs ()) {
594+ assert orig .scroll () == null ;
595+ ShardSearchRequest clone = new ShardSearchRequest (orig );
596+ CanMatchContext canMatchContext = new CanMatchContext (
597+ clone ,
598+ indicesService ::indexServiceSafe ,
599+ this ::findReaderContext ,
600+ defaultKeepAlive ,
601+ maxKeepAlive
602+ );
603+ CanMatchShardResponse canMatchResp = canMatch (canMatchContext , false );
604+ if (canMatchResp .canMatch () == false ) {
605+ l .onResponse (QuerySearchResult .nullInstance ());
606+ return ;
607+ }
605608 }
606- }
607- // TODO: i think it makes sense to always do a canMatch here and
608- // return an empty response (not null response) in case canMatch is false?
609- ensureAfterSeqNoRefreshed ( shard , orig , () -> executeQueryPhase ( orig , task ), l );
610- }) );
609+ // TODO: i think it makes sense to always do a canMatch here and
610+ // return an empty response (not null response) in case canMatch is false?
611+ ensureAfterSeqNoRefreshed ( shard , orig , () -> executeQueryPhase ( orig , task ), l );
612+ })
613+ );
611614 }
612615
613616 private <T extends RefCounted > void ensureAfterSeqNoRefreshed (
0 commit comments