@@ -330,7 +330,6 @@ public void testMergeAggs() throws InterruptedException {
330
330
assertEquals (totalCount , bucket .getDocCount ());
331
331
}
332
332
333
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/40553" )
334
333
public void testMergeSearchHits () throws InterruptedException {
335
334
final long currentRelativeTime = randomLong ();
336
335
final SearchTimeProvider timeProvider = new SearchTimeProvider (randomLong (), 0 , () -> currentRelativeTime );
@@ -376,6 +375,7 @@ public void testMergeSearchHits() throws InterruptedException {
376
375
float expectedMaxScore = Float .NEGATIVE_INFINITY ;
377
376
int numIndices = requestedSize == 0 ? 0 : randomIntBetween (1 , requestedSize );
378
377
Iterator <Map .Entry <String , Index []>> indicesIterator = randomRealisticIndices (numIndices , numResponses ).entrySet ().iterator ();
378
+ boolean hasHits = false ;
379
379
for (int i = 0 ; i < numResponses ; i ++) {
380
380
Map .Entry <String , Index []> entry = indicesIterator .next ();
381
381
String clusterAlias = entry .getKey ();
@@ -399,6 +399,7 @@ public void testMergeSearchHits() throws InterruptedException {
399
399
float maxScore = scoreSort ? numDocs * scoreFactor : Float .NaN ;
400
400
SearchHit [] hits = randomSearchHitArray (numDocs , numResponses , clusterAlias , indices , maxScore , scoreFactor ,
401
401
sortFields , priorityQueue );
402
+ hasHits |= hits .length > 0 ;
402
403
expectedMaxScore = Math .max (expectedMaxScore , maxScore );
403
404
404
405
Object [] collapseValues = null ;
@@ -448,7 +449,7 @@ public void testMergeSearchHits() throws InterruptedException {
448
449
449
450
SearchHits searchHits = searchResponse .getHits ();
450
451
// the sort fields and the collapse field are not returned when hits are empty
451
- if (searchHits . getHits (). length > 0 ) {
452
+ if (hasHits ) {
452
453
assertArrayEquals (sortFields , searchHits .getSortFields ());
453
454
assertEquals (collapseField , searchHits .getCollapseField ());
454
455
} else {
@@ -474,7 +475,7 @@ public void testMergeSearchHits() throws InterruptedException {
474
475
SearchHit [] hits = searchHits .getHits ();
475
476
if (collapseField != null
476
477
// the collapse field is not returned when hits are empty
477
- && hits . length > 0 ) {
478
+ && hasHits ) {
478
479
assertEquals (hits .length , searchHits .getCollapseValues ().length );
479
480
} else {
480
481
assertNull (searchHits .getCollapseValues ());
0 commit comments