For filters aggs, make sure that rewrites preserve other_bucket. (#32921)
This commit is contained in:
parent
0876630b30
commit
cbf160a4e6
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue