From bcdd7d5f42e94c1e8d0e7075c19ba5f327133a1a Mon Sep 17 00:00:00 2001 From: Ignacio Vera Date: Mon, 25 Sep 2023 09:29:27 +0200 Subject: [PATCH] Set ParentAggregationBuilder not to support concurrent execution (#99809) --- .../join/aggregations/ChildrenIT.java | 16 ++++++++++++-- .../join/aggregations/ParentIT.java | 22 ++++++++++++++++++- .../ParentAggregationBuilder.java | 5 +++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/aggregations/ChildrenIT.java b/modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/aggregations/ChildrenIT.java index afb7ad702de9c..49d3d04b3ee5c 100644 --- a/modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/aggregations/ChildrenIT.java +++ b/modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/aggregations/ChildrenIT.java @@ -9,6 +9,7 @@ import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.client.internal.Requests; @@ -43,7 +44,18 @@ public class ChildrenIT extends AbstractParentChildTestCase { - public void testChildrenAggs() throws Exception { + public void testSimpleChildrenAgg() { + final SearchRequestBuilder searchRequest = client().prepareSearch("test") + .setQuery(matchQuery("randomized", true)) + .addAggregation(children("to_comment", "comment")); + final SearchResponse searchResponse = searchRequest.get(); + long count = categoryToControl.values().stream().mapToLong(control -> control.commentIds.size()).sum(); + assertSearchResponse(searchResponse); + Children childrenAgg = searchResponse.getAggregations().get("to_comment"); + assertThat("Request: " + searchRequest + "\nResponse: " + searchResponse + "\n", childrenAgg.getDocCount(), equalTo(count)); + } + + public void testChildrenAggs() { SearchResponse searchResponse = client().prepareSearch("test") .setQuery(matchQuery("randomized", true)) .addAggregation( @@ -86,7 +98,7 @@ public void testChildrenAggs() throws Exception { } } - public void testParentWithMultipleBuckets() throws Exception { + public void testParentWithMultipleBuckets() { SearchResponse searchResponse = client().prepareSearch("test") .setQuery(matchQuery("randomized", false)) .addAggregation( diff --git a/modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/aggregations/ParentIT.java b/modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/aggregations/ParentIT.java index 5c409179f4e18..26a8d44759513 100644 --- a/modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/aggregations/ParentIT.java +++ b/modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/aggregations/ParentIT.java @@ -32,7 +32,27 @@ public class ParentIT extends AbstractParentChildTestCase { - public void testSimpleParentAgg() throws Exception { + public void testSimpleParentAgg() { + final SearchRequestBuilder searchRequest = client().prepareSearch("test") + .setSize(0) + .setQuery(matchQuery("randomized", true)) + .addAggregation(parent("to_article", "comment")); + SearchResponse searchResponse = searchRequest.get(); + + assertSearchResponse(searchResponse); + long articlesWithComment = articleToControl.values() + .stream() + .filter(parentControl -> parentControl.commentIds.isEmpty() == false) + .count(); + Parent parentAgg = searchResponse.getAggregations().get("to_article"); + assertThat( + "Request: " + searchRequest + "\nResponse: " + searchResponse + "\n", + parentAgg.getDocCount(), + equalTo(articlesWithComment) + ); + } + + public void testSimpleParentAggWithSubAgg() { final SearchRequestBuilder searchRequest = client().prepareSearch("test") .setSize(10000) .setQuery(matchQuery("randomized", true)) diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregationBuilder.java b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregationBuilder.java index c5a285de70577..d608efcba9b83 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregationBuilder.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/ParentAggregationBuilder.java @@ -90,6 +90,11 @@ public BucketCardinality bucketCardinality() { return BucketCardinality.ONE; } + @Override + public boolean supportsParallelCollection() { + return false; + } + @Override protected ValuesSourceAggregatorFactory innerBuild( AggregationContext context,