diff --git a/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenToParentAggregatorTests.java b/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenToParentAggregatorTests.java index f047bae6a95c8..f64f8880f9ce9 100644 --- a/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenToParentAggregatorTests.java +++ b/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ChildrenToParentAggregatorTests.java @@ -32,7 +32,6 @@ import org.apache.lucene.search.TermInSetQuery; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.collect.Tuple; @@ -40,12 +39,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.mapper.ContentPath; -import org.elasticsearch.index.mapper.MappingLookup; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.IdFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.Mapper; import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.index.mapper.MappingLookup; import org.elasticsearch.index.mapper.NumberFieldMapper; import org.elasticsearch.index.mapper.Uid; import org.elasticsearch.index.shard.ShardId; @@ -75,7 +74,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/60980") public class ChildrenToParentAggregatorTests extends AggregatorTestCase { private static final String CHILD_TYPE = "child_type"; @@ -121,9 +119,11 @@ public void testParentChild() throws IOException { expectedTotalParents++; expectedMinValue = Math.min(expectedMinValue, expectedValues.v2()); } - assertEquals("Having " + parent.getDocCount() + " docs and aggregation results: " + - parent.getAggregations().asMap(), - expectedTotalParents, parent.getDocCount()); + assertEquals( + "Having " + parent.getDocCount() + " docs and aggregation results: " + parent, + expectedTotalParents, + parent.getDocCount() + ); assertEquals(expectedMinValue, ((InternalMin) parent.getAggregations().get("in_parent")).getValue(), Double.MIN_VALUE); assertTrue(JoinAggregationInspectionHelper.hasValue(parent)); }); @@ -235,21 +235,19 @@ private static Map> setupIndex(RandomIndexWriter Map> expectedValues = new HashMap<>(); int numParents = randomIntBetween(1, 10); for (int i = 0; i < numParents; i++) { + List> documents = new ArrayList<>(); String parent = "parent" + i; int randomValue = randomIntBetween(0, 100); - List parentDocument = createParentDocument(parent, randomValue); - /*long parentDocId =*/ iw.addDocument(parentDocument); - //System.out.println("Parent: " + parent + ": " + randomValue + ", id: " + parentDocId); + documents.add(createParentDocument(parent, randomValue)); int numChildren = randomIntBetween(1, 10); int minValue = Integer.MAX_VALUE; for (int c = 0; c < numChildren; c++) { minValue = Math.min(minValue, randomValue); int randomSubValue = randomIntBetween(0, 100); - List childDocument = createChildDocument("child" + c + "_" + parent, parent, randomSubValue); - /*long childDocId =*/ iw.addDocument(childDocument); - //System.out.println("Child: " + "child" + c + "_" + parent + ": " + randomSubValue + ", id: " + childDocId); + documents.add(createChildDocument("child" + c + "_" + parent, parent, randomSubValue)); } expectedValues.put(parent, new Tuple<>(numChildren, minValue)); + iw.addDocuments(documents); } return expectedValues; } diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java index c7782e14311db..5f8c910da6339 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java @@ -424,9 +424,12 @@ protected A searchAndReduc } /** - * Divides the provided {@link IndexSearcher} in sub-searcher, one for each segment, - * builds an aggregator for each sub-searcher filtered by the provided {@link Query} and + * Collects all documents that match the provided query {@link Query} and * returns the reduced {@link InternalAggregation}. + *

+ * Half the time it aggregates each leaf individually and reduces all + * results together. The other half the time it aggregates across the entire + * index at once and runs a final reduction on the single resulting agg. */ protected A searchAndReduce(IndexSettings indexSettings, IndexSearcher searcher,