From 263cf6f9947f9d9f94fe43bff098a15338318acc Mon Sep 17 00:00:00 2001 From: iverase Date: Fri, 22 Sep 2023 13:54:50 +0200 Subject: [PATCH 1/2] Set ParentAggregationBuilder as not supporting concurrent execution --- .../join/aggregations/ParentIT.java | 31 ++++++++++++++++--- .../ParentAggregationBuilder.java | 5 +++ 2 files changed, 31 insertions(+), 5 deletions(-) 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..dfe0f07adf82f 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,25 +32,46 @@ public class ParentIT extends AbstractParentChildTestCase { - public void testSimpleParentAgg() throws Exception { + public void testSimpleParentAgg() { final SearchRequestBuilder searchRequest = client().prepareSearch("test") - .setSize(10000) + .setSize(0) .setQuery(matchQuery("randomized", true)) - .addAggregation(parent("to_article", "comment").subAggregation(terms("category").field("category").size(10000))); + .addAggregation(parent("to_article", "comment")); SearchResponse searchResponse = searchRequest.get(); - assertSearchResponse(searchResponse); + 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)) + .addAggregation(parent("to_article", "comment").subAggregation(terms("category").field("category").size(10000))); + 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) + ); Terms categoryTerms = parentAgg.getAggregations().get("category"); long categoriesWithComments = categoryToControl.values().stream().filter(control -> control.commentIds.isEmpty() == false).count(); assertThat( 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, From 111f362cbfc2c125de2148e4d53471b55522b2a9 Mon Sep 17 00:00:00 2001 From: iverase Date: Fri, 22 Sep 2023 14:18:17 +0200 Subject: [PATCH 2/2] spotless --- .../join/aggregations/ChildrenIT.java | 16 ++++++++++-- .../join/aggregations/ParentIT.java | 25 +++++++++---------- 2 files changed, 26 insertions(+), 15 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 dfe0f07adf82f..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 @@ -52,21 +52,20 @@ public void testSimpleParentAgg() { ); } - public void testSimpleParentAggWithSubAgg() { - final SearchRequestBuilder searchRequest = client().prepareSearch("test") - .setSize(10000) - .setQuery(matchQuery("randomized", true)) - .addAggregation(parent("to_article", "comment").subAggregation(terms("category").field("category").size(10000))); - SearchResponse searchResponse = searchRequest.get(); - assertSearchResponse(searchResponse); - - long articlesWithComment = articleToControl.values() - .stream() - .filter(parentControl -> parentControl.commentIds.isEmpty() == false) - .count(); + final SearchRequestBuilder searchRequest = client().prepareSearch("test") + .setSize(10000) + .setQuery(matchQuery("randomized", true)) + .addAggregation(parent("to_article", "comment").subAggregation(terms("category").field("category").size(10000))); + SearchResponse searchResponse = searchRequest.get(); + assertSearchResponse(searchResponse); - Parent parentAgg = searchResponse.getAggregations().get("to_article"); + 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(),