@@ -396,7 +396,6 @@ public void testMergeAggs() throws InterruptedException {
396
396
assertEquals (totalCount , bucket .getDocCount ());
397
397
}
398
398
399
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/40553" )
400
399
public void testMergeSearchHits () throws InterruptedException {
401
400
final long currentRelativeTime = randomLong ();
402
401
final SearchTimeProvider timeProvider = new SearchTimeProvider (randomLong (), 0 , () -> currentRelativeTime );
@@ -442,6 +441,7 @@ public void testMergeSearchHits() throws InterruptedException {
442
441
float expectedMaxScore = Float .NEGATIVE_INFINITY ;
443
442
int numIndices = requestedSize == 0 ? 0 : randomIntBetween (1 , requestedSize );
444
443
Iterator <Map .Entry <String , Index []>> indicesIterator = randomRealisticIndices (numIndices , numResponses ).entrySet ().iterator ();
444
+ boolean hasHits = false ;
445
445
for (int i = 0 ; i < numResponses ; i ++) {
446
446
Map .Entry <String , Index []> entry = indicesIterator .next ();
447
447
String clusterAlias = entry .getKey ();
@@ -465,6 +465,7 @@ public void testMergeSearchHits() throws InterruptedException {
465
465
float maxScore = scoreSort ? numDocs * scoreFactor : Float .NaN ;
466
466
SearchHit [] hits = randomSearchHitArray (numDocs , numResponses , clusterAlias , indices , maxScore , scoreFactor ,
467
467
sortFields , priorityQueue );
468
+ hasHits |= hits .length > 0 ;
468
469
expectedMaxScore = Math .max (expectedMaxScore , maxScore );
469
470
470
471
Object [] collapseValues = null ;
@@ -514,7 +515,7 @@ public void testMergeSearchHits() throws InterruptedException {
514
515
515
516
SearchHits searchHits = searchResponse .getHits ();
516
517
// the sort fields and the collapse field are not returned when hits are empty
517
- if (searchHits . getHits (). length > 0 ) {
518
+ if (hasHits ) {
518
519
assertArrayEquals (sortFields , searchHits .getSortFields ());
519
520
assertEquals (collapseField , searchHits .getCollapseField ());
520
521
} else {
@@ -540,7 +541,7 @@ public void testMergeSearchHits() throws InterruptedException {
540
541
SearchHit [] hits = searchHits .getHits ();
541
542
if (collapseField != null
542
543
// the collapse field is not returned when hits are empty
543
- && hits . length > 0 ) {
544
+ && hasHits ) {
544
545
assertEquals (hits .length , searchHits .getCollapseValues ().length );
545
546
} else {
546
547
assertNull (searchHits .getCollapseValues ());
0 commit comments