@@ -396,7 +396,6 @@ public void testMergeAggs() throws InterruptedException {
396396 assertEquals (totalCount , bucket .getDocCount ());
397397 }
398398
399- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/40553" )
400399 public void testMergeSearchHits () throws InterruptedException {
401400 final long currentRelativeTime = randomLong ();
402401 final SearchTimeProvider timeProvider = new SearchTimeProvider (randomLong (), 0 , () -> currentRelativeTime );
@@ -442,6 +441,7 @@ public void testMergeSearchHits() throws InterruptedException {
442441 float expectedMaxScore = Float .NEGATIVE_INFINITY ;
443442 int numIndices = requestedSize == 0 ? 0 : randomIntBetween (1 , requestedSize );
444443 Iterator <Map .Entry <String , Index []>> indicesIterator = randomRealisticIndices (numIndices , numResponses ).entrySet ().iterator ();
444+ boolean hasHits = false ;
445445 for (int i = 0 ; i < numResponses ; i ++) {
446446 Map .Entry <String , Index []> entry = indicesIterator .next ();
447447 String clusterAlias = entry .getKey ();
@@ -465,6 +465,7 @@ public void testMergeSearchHits() throws InterruptedException {
465465 float maxScore = scoreSort ? numDocs * scoreFactor : Float .NaN ;
466466 SearchHit [] hits = randomSearchHitArray (numDocs , numResponses , clusterAlias , indices , maxScore , scoreFactor ,
467467 sortFields , priorityQueue );
468+ hasHits |= hits .length > 0 ;
468469 expectedMaxScore = Math .max (expectedMaxScore , maxScore );
469470
470471 Object [] collapseValues = null ;
@@ -514,7 +515,7 @@ public void testMergeSearchHits() throws InterruptedException {
514515
515516 SearchHits searchHits = searchResponse .getHits ();
516517 // the sort fields and the collapse field are not returned when hits are empty
517- if (searchHits . getHits (). length > 0 ) {
518+ if (hasHits ) {
518519 assertArrayEquals (sortFields , searchHits .getSortFields ());
519520 assertEquals (collapseField , searchHits .getCollapseField ());
520521 } else {
@@ -540,7 +541,7 @@ public void testMergeSearchHits() throws InterruptedException {
540541 SearchHit [] hits = searchHits .getHits ();
541542 if (collapseField != null
542543 // the collapse field is not returned when hits are empty
543- && hits . length > 0 ) {
544+ && hasHits ) {
544545 assertEquals (hits .length , searchHits .getCollapseValues ().length );
545546 } else {
546547 assertNull (searchHits .getCollapseValues ());
0 commit comments