Skip to content

Commit

Permalink
add ChildAggregation test
Browse files Browse the repository at this point in the history
Signed-off-by: Siva <ychnagasivareddy@gmail.com>
  • Loading branch information
sivaGH3 committed Dec 29, 2022
1 parent 46e0ce2 commit 1cdba16
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,28 @@ public void testSubAggregation() throws IOException {

}

@Test
public void testChildAggregation() throws IOException {

String index = "test_child";
String question = "question";
String answer = "answer";
Map<String, List<String>> relations = Collections.singletonMap(question, Collections.singletonList(answer));

highLevelClient().indices().create(c -> c.index(index).mappings(m -> m.properties("join", p -> p.join(j -> j.relations(relations)))));

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 +491,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);
}
}
}

0 comments on commit 1cdba16

Please sign in to comment.