@@ -468,27 +468,12 @@ protected void doRun(Map<SearchShardIterator, Integer> shardIndexMap) {
468468 @ Override
469469 protected void doRun () {
470470 if (hasPrimaryFieldSort (request .source ())) {
471- var pitBuilder = request .pointInTimeBuilder ();
472471 @ SuppressWarnings ("rawtypes" )
473472 final MinAndMax [] minAndMax = new MinAndMax [localNodeRequest .shards .size ()];
474473 for (int i = 0 ; i < minAndMax .length ; i ++) {
475- var shardToQuery = localNodeRequest .shards .get (i );
476- var shardId = shardToQuery .shardId ;
477- var r = buildShardSearchRequest (
478- shardId ,
479- localNodeRequest .localClusterAlias ,
480- shardToQuery .shardIndex ,
481- shardToQuery .contextId ,
482- new OriginalIndices (shardToQuery .originalIndices , request .indicesOptions ()),
483- localNodeRequest .aliasFilters .getOrDefault (shardId .getIndex ().getUUID (), AliasFilter .EMPTY ),
484- pitBuilder == null ? null : pitBuilder .getKeepAlive (),
485- shardToQuery .boost ,
486- request ,
487- localNodeRequest .totalShards ,
488- localNodeRequest .absoluteStartMillis ,
489- false
490- );
491- minAndMax [i ] = searchService .canMatch (r ).estimatedMinAndMax ();
474+ minAndMax [i ] = searchService .canMatch (
475+ buildShardSearchRequestForLocal (localNodeRequest , localNodeRequest .shards .get (i ))
476+ ).estimatedMinAndMax ();
492477 }
493478 try {
494479 int [] indexes = CanMatchPreFilterSearchPhase .sortShards (
@@ -597,6 +582,26 @@ public void handleException(TransportException e) {
597582 });
598583 }
599584
585+ private static ShardSearchRequest buildShardSearchRequestForLocal (NodeQueryRequest nodeQueryRequest , ShardToQuery shardToQuery ) {
586+ var shardId = shardToQuery .shardId ;
587+ var searchRequest = nodeQueryRequest .searchRequest ;
588+ var pitBuilder = searchRequest .pointInTimeBuilder ();
589+ return buildShardSearchRequest (
590+ shardId ,
591+ nodeQueryRequest .localClusterAlias ,
592+ shardToQuery .shardIndex ,
593+ shardToQuery .contextId ,
594+ new OriginalIndices (shardToQuery .originalIndices , searchRequest .indicesOptions ()),
595+ nodeQueryRequest .aliasFilters .getOrDefault (shardId .getIndex ().getUUID (), AliasFilter .EMPTY ),
596+ pitBuilder == null ? null : pitBuilder .getKeepAlive (),
597+ shardToQuery .boost ,
598+ searchRequest ,
599+ nodeQueryRequest .totalShards ,
600+ nodeQueryRequest .absoluteStartMillis ,
601+ false
602+ );
603+ }
604+
600605 public static boolean connectionSupportsBatchedExecution (Transport .Connection connection ) {
601606 return connection .getTransportVersion ().onOrAfter (TransportVersions .BATCHED_QUERY_PHASE_VERSION )
602607 || connection .getNode ().getVersionInformation ().nodeVersion ().onOrAfter (Version .V_9_1_0 );
@@ -647,26 +652,10 @@ static void registerNodeSearchAction(
647652 final ShardSearchRequest [] shardSearchRequests ;
648653 if (hasPrimaryFieldSort (searchRequest .source ())) {
649654 shardSearchRequests = new ShardSearchRequest [request .shards .size ()];
650- var pitBuilder = searchRequest .pointInTimeBuilder ();
651655 @ SuppressWarnings ("rawtypes" )
652656 final MinAndMax [] minAndMax = new MinAndMax [request .shards .size ()];
653657 for (int i = 0 ; i < minAndMax .length ; i ++) {
654- var shardToQuery = request .shards .get (i );
655- var shardId = shardToQuery .shardId ;
656- var r = buildShardSearchRequest (
657- shardId ,
658- request .localClusterAlias ,
659- shardToQuery .shardIndex ,
660- shardToQuery .contextId ,
661- new OriginalIndices (shardToQuery .originalIndices , request .indicesOptions ()),
662- request .aliasFilters .getOrDefault (shardId .getIndex ().getUUID (), AliasFilter .EMPTY ),
663- pitBuilder == null ? null : pitBuilder .getKeepAlive (),
664- shardToQuery .boost ,
665- searchRequest ,
666- request .totalShards ,
667- request .absoluteStartMillis ,
668- false
669- );
658+ ShardSearchRequest r = buildShardSearchRequestForLocal (request , request .shards .get (i ));
670659 shardSearchRequests [i ] = r ;
671660 minAndMax [i ] = searchService .canMatch (r ).estimatedMinAndMax ();
672661 }
0 commit comments