Skip to content

Commit

Permalink
For filters aggs, make sure that rewrites preserve other_bucket. (#32921
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jtibshirani committed Aug 17, 2018
1 parent 3c27d59 commit 813b189
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ protected AggregationBuilder doRewrite(QueryRewriteContext queryShardContext) th
}
}
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,18 @@ public void testRewrite() throws IOException {
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());
}
}

0 comments on commit 813b189

Please sign in to comment.