Skip to content

Commit

Permalink
Fix a test bug around nested aggregations and field aliases. (elastic…
Browse files Browse the repository at this point in the history
…#32287)

This issue affected both NestedAggregatorTest and ReverseNestedAggregatorTest.
  • Loading branch information
jtibshirani committed Jul 24, 2018
1 parent 142be2e commit 301adfd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ public void testPreGetChildLeafCollectors() throws IOException {

public void testFieldAlias() throws IOException {
int numRootDocs = randomIntBetween(1, 20);
int expectedNestedDocs = 0;

MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(
NumberFieldMapper.NumberType.LONG);
Expand All @@ -669,6 +670,7 @@ public void testFieldAlias() throws IOException {
for (int i = 0; i < numRootDocs; i++) {
List<Document> documents = new ArrayList<>();
int numNestedDocs = randomIntBetween(0, 20);
expectedNestedDocs += numNestedDocs;
generateDocuments(documents, numNestedDocs, i, NESTED_OBJECT, VALUE_FIELD_NAME);

Document document = new Document();
Expand All @@ -685,7 +687,6 @@ public void testFieldAlias() throws IOException {
try (IndexReader indexReader = wrap(DirectoryReader.open(directory))) {
NestedAggregationBuilder agg = nested(NESTED_AGG, NESTED_OBJECT).subAggregation(
max(MAX_AGG_NAME).field(VALUE_FIELD_NAME));

NestedAggregationBuilder aliasAgg = nested(NESTED_AGG, NESTED_OBJECT).subAggregation(
max(MAX_AGG_NAME).field(VALUE_FIELD_NAME + "-alias"));

Expand All @@ -694,8 +695,8 @@ public void testFieldAlias() throws IOException {
Nested aliasNested = search(newSearcher(indexReader, false, true),
new MatchAllDocsQuery(), aliasAgg, fieldType);

assertTrue(nested.getDocCount() > 0);
assertEquals(nested, aliasNested);
assertEquals(expectedNestedDocs, nested.getDocCount());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public void testMaxFromParentDocs() throws IOException {

public void testFieldAlias() throws IOException {
int numParentDocs = randomIntBetween(1, 20);
int expectedParentDocs = 0;

MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(
NumberFieldMapper.NumberType.LONG);
Expand All @@ -180,6 +181,10 @@ public void testFieldAlias() throws IOException {
for (int i = 0; i < numParentDocs; i++) {
List<Document> documents = new ArrayList<>();
int numNestedDocs = randomIntBetween(0, 20);
if (numNestedDocs > 0) {
expectedParentDocs++;
}

for (int nested = 0; nested < numNestedDocs; nested++) {
Document document = new Document();
document.add(new Field(IdFieldMapper.NAME, Uid.encodeId(Integer.toString(i)),
Expand All @@ -204,7 +209,6 @@ public void testFieldAlias() throws IOException {
}

try (IndexReader indexReader = wrap(DirectoryReader.open(directory))) {

MaxAggregationBuilder maxAgg = max(MAX_AGG_NAME).field(VALUE_FIELD_NAME);
MaxAggregationBuilder aliasMaxAgg = max(MAX_AGG_NAME).field(VALUE_FIELD_NAME + "-alias");

Expand All @@ -221,8 +225,8 @@ public void testFieldAlias() throws IOException {
ReverseNested reverseNested = nested.getAggregations().get(REVERSE_AGG_NAME);
ReverseNested aliasReverseNested = aliasNested.getAggregations().get(REVERSE_AGG_NAME);

assertTrue(reverseNested.getDocCount() > 0);
assertEquals(reverseNested, aliasReverseNested);
assertEquals(expectedParentDocs, reverseNested.getDocCount());
}
}
}
Expand Down

0 comments on commit 301adfd

Please sign in to comment.