For filters aggs, make sure that rewrites preserve other_bucket. (#32921)

This commit is contained in:
Julie Tibshirani 2018-08-16 17:36:58 -07:00 committed by GitHub
parent 0876630b30
commit cbf160a4e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -209,7 +209,10 @@ public class FiltersAggregationBuilder extends AbstractAggregationBuilder<Filter
}
}
if (changed) {
return new FiltersAggregationBuilder(getName(), rewrittenFilters, this.keyed);
FiltersAggregationBuilder rewritten = new FiltersAggregationBuilder(getName(), rewrittenFilters, this.keyed);
rewritten.otherBucket(otherBucket);
rewritten.otherBucketKey(otherBucketKey);
return rewritten;
} else {
return this;
}

View File

@ -178,4 +178,18 @@ public class FiltersTests extends BaseAggregationTestCase<FiltersAggregationBuil
assertSame(rewritten,
rewritten.rewrite(new QueryRewriteContext(xContentRegistry(), null, null, () -> 0L)));
}
public void testRewritePreservesOtherBucket() throws IOException {
FiltersAggregationBuilder originalFilters = new FiltersAggregationBuilder("my-agg", new BoolQueryBuilder());
originalFilters.otherBucket(randomBoolean());
originalFilters.otherBucketKey(randomAlphaOfLength(10));
AggregationBuilder rewritten = originalFilters.rewrite(new QueryRewriteContext(xContentRegistry(),
null, null, () -> 0L));
assertThat(rewritten, instanceOf(FiltersAggregationBuilder.class));
FiltersAggregationBuilder rewrittenFilters = (FiltersAggregationBuilder) rewritten;
assertEquals(originalFilters.otherBucket(), rewrittenFilters.otherBucket());
assertEquals(originalFilters.otherBucketKey(), rewrittenFilters.otherBucketKey());
}
}