Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Make ChildrenAggregate as a SingleBucketAggregate #306

Merged
merged 4 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Removed
- Removed support for unsupported dynamic_templates in bulk ([#276](https://github.com/opensearch-project/opensearch-java/pull/276))

### Fixed
- Make ChildrenAggregate as a SingleBucketAggregate ([#306](https://github.com/opensearch-project/opensearch-java/pull/306))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
// typedef: _types.aggregations.ChildrenAggregate

@JsonpDeserializable
public class ChildrenAggregate extends MultiBucketAggregateBase<ChildrenAggregateBucket> implements AggregateVariant {
public class ChildrenAggregate extends SingleBucketAggregateBase implements AggregateVariant {
// ---------------------------------------------------------------------------------------------

private ChildrenAggregate(Builder builder) {
Expand All @@ -73,7 +73,7 @@ public Aggregate.Kind _aggregateKind() {
* Builder for {@link ChildrenAggregate}.
*/

public static class Builder extends MultiBucketAggregateBase.AbstractBuilder<ChildrenAggregateBucket, Builder>
public static class Builder extends SingleBucketAggregateBase.AbstractBuilder<Builder>
implements
ObjectBuilder<ChildrenAggregate> {
@Override
Expand All @@ -89,7 +89,6 @@ protected Builder self() {
*/
public ChildrenAggregate build() {
_checkSingleUse();
super.tBucketSerializer(null);

return new ChildrenAggregate(this);
}
Expand All @@ -104,8 +103,7 @@ public ChildrenAggregate build() {
.lazy(Builder::new, ChildrenAggregate::setupChildrenAggregateDeserializer);

protected static void setupChildrenAggregateDeserializer(ObjectDeserializer<ChildrenAggregate.Builder> op) {
MultiBucketAggregateBase.setupMultiBucketAggregateBaseDeserializer(op, ChildrenAggregateBucket._DESERIALIZER);

SingleBucketAggregateBase.setupSingleBucketAggregateBaseDeserializer(op);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,27 @@ public void testSubAggregation() throws IOException {

}

@Test
public void testChildAggregation() throws IOException {

String index = "test_child";
String question = "question";
String answer = "answer";

highLevelClient().indices().create(c -> c.index(index).mappings(m -> m.properties("join", p -> p
.join(j -> j.relations(Collections.singletonMap(question, Collections.singletonList(answer)))))));
highLevelClient().index(i -> i.index(index).id("1").document(new Question("exists")).refresh(Refresh.True));
highLevelClient().index(i -> i.index(index).id("2").routing("1").document(new Answer("true", "1")).refresh(Refresh.True));
highLevelClient().index(i -> i.index(index).id("3").routing("1").document(new Answer("false", "1")).refresh(Refresh.True));

SearchRequest searchRequest = SearchRequest.of(r -> r.index(index).size(0)
.aggregations(answer, a -> a.children(c -> c.type(answer))));

SearchResponse<Void> searchResponse = highLevelClient().search(searchRequest, Void.class);

assertEquals(2, searchResponse.aggregations().get(answer).children().docCount());
}

@Test
public void testGetMapping() throws Exception {
// See also VariantsTest.testNestedTaggedUnionWithDefaultTag()
Expand Down Expand Up @@ -469,4 +490,48 @@ public void setPrice(double price) {
this.price = price;
}
}

public static class Join {
public String name;
public String parent;

Join() {}

Join(String name) {
this.name = name;
}

Join(String name, String parent) {
this.name = name;
this.parent = parent;
}
}

public static class Question {
public String title;
public Join join;

Question() {}

Question(String title) {
this.title = title;
this.join = new Join("question");
}
}

public static class Answer {
public String body;
public Join join;

Answer() {}

Answer(String body) {
this.body = body;
}

Answer(String body, String parent) {
this.body = body;
this.join = new Join("answer", parent);
}
}
}