diff --git a/src/Aggregation/FilterAggregation.php b/src/Aggregation/FilterAggregation.php index 2e512baa6e30bc603fd492bc56c164763b643c1e..362e5961cf4b6991bfafd70a0475a8f634704812 100644 --- a/src/Aggregation/FilterAggregation.php +++ b/src/Aggregation/FilterAggregation.php @@ -13,6 +13,7 @@ namespace ONGR\ElasticsearchDSL\Aggregation; use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait; use ONGR\ElasticsearchDSL\BuilderInterface; +use ONGR\ElasticsearchDSL\Filter\BoolFilter; /** * Class representing FilterAggregation. @@ -68,7 +69,12 @@ class FilterAggregation extends AbstractAggregation throw new \LogicException("Filter aggregation `{$this->getName()}` has no filter added"); } - $filterData = [$this->filter->getType() => $this->filter->toArray()]; + if ($this->filter instanceof BoolFilter && $this->filter->isRelevant() || + !$this->filter instanceof BoolFilter) { + $filterData = [$this->filter->getType() => $this->filter->toArray()]; + } else { + $filterData = $this->filter->toArray(); + } return $filterData; }