Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregatorFactory;
import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregatorFactory;
import org.elasticsearch.search.internal.SearchContext;

Expand Down Expand Up @@ -155,13 +156,22 @@ public int size() {
/**
* Returns null if the provided factory and his parents are compatible with
* this aggregator or the instance of the parent's factory that is incompatible with
* the composite aggregation.
* the composite aggregation. A composite aggregation can be used as a child of a nested
* aggregation and as a child of a filter only if the parent of the filter is a
* nested aggregation.
*
* @return null if compatible
*/
private AggregatorFactory<?> checkParentIsNullOrNested(AggregatorFactory<?> factory) {
if (factory == null) {
return null;
} else if (factory instanceof NestedAggregatorFactory) {
return checkParentIsNullOrNested(factory.getParent());
} else if (factory instanceof NestedAggregatorFactory &&
factory.getParent() == null) {
return null;
} else if (factory instanceof FilterAggregatorFactory &&
factory.getParent() instanceof NestedAggregatorFactory &&
factory.getParent().getParent() == null) {
return null;
} else {
return factory;
}
Expand Down