Skip to content

Commit

Permalink
Set ParentAggregationBuilder not to support concurrent execution (ela…
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase authored Sep 25, 2023
1 parent db985e4 commit bcdd7d5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public BucketCardinality bucketCardinality() {
return BucketCardinality.ONE;
}

@Override
public boolean supportsParallelCollection() {
return false;
}

@Override
protected ValuesSourceAggregatorFactory innerBuild(
AggregationContext context,
Expand Down

0 comments on commit bcdd7d5

Please sign in to comment.