diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchResponseMergerTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchResponseMergerTests.java index 26a022c0d7745..ab31c44ff2d59 100644 --- a/server/src/test/java/org/elasticsearch/action/search/SearchResponseMergerTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/SearchResponseMergerTests.java @@ -396,7 +396,6 @@ public void testMergeAggs() throws InterruptedException { assertEquals(totalCount, bucket.getDocCount()); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/40553") public void testMergeSearchHits() throws InterruptedException { final long currentRelativeTime = randomLong(); final SearchTimeProvider timeProvider = new SearchTimeProvider(randomLong(), 0, () -> currentRelativeTime); @@ -442,6 +441,7 @@ public void testMergeSearchHits() throws InterruptedException { float expectedMaxScore = Float.NEGATIVE_INFINITY; int numIndices = requestedSize == 0 ? 0 : randomIntBetween(1, requestedSize); Iterator> indicesIterator = randomRealisticIndices(numIndices, numResponses).entrySet().iterator(); + boolean hasHits = false; for (int i = 0; i < numResponses; i++) { Map.Entry entry = indicesIterator.next(); String clusterAlias = entry.getKey(); @@ -465,6 +465,7 @@ public void testMergeSearchHits() throws InterruptedException { float maxScore = scoreSort ? numDocs * scoreFactor : Float.NaN; SearchHit[] hits = randomSearchHitArray(numDocs, numResponses, clusterAlias, indices, maxScore, scoreFactor, sortFields, priorityQueue); + hasHits |= hits.length > 0; expectedMaxScore = Math.max(expectedMaxScore, maxScore); Object[] collapseValues = null; @@ -514,7 +515,7 @@ public void testMergeSearchHits() throws InterruptedException { SearchHits searchHits = searchResponse.getHits(); // the sort fields and the collapse field are not returned when hits are empty - if (searchHits.getHits().length > 0) { + if (hasHits) { assertArrayEquals(sortFields, searchHits.getSortFields()); assertEquals(collapseField, searchHits.getCollapseField()); } else { @@ -540,7 +541,7 @@ public void testMergeSearchHits() throws InterruptedException { SearchHit[] hits = searchHits.getHits(); if (collapseField != null // the collapse field is not returned when hits are empty - && hits.length > 0) { + && hasHits) { assertEquals(hits.length, searchHits.getCollapseValues().length); } else { assertNull(searchHits.getCollapseValues());