Skip to content

Commit 2345bc2

Browse files
committed
Different behaviour with filter
1 parent be78202 commit 2345bc2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Aggregation/LeafAggregationCollection.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,21 @@ public function getIterator() : \ArrayIterator
5959
public function toArray() : array
6060
{
6161
$array = [];
62+
$hasFilter = $this->filter && \count($this->filter->toArray());
6263

6364
foreach ($this->aggregations as $aggregation) {
6465
if ($aggregation instanceof \Spameri\ElasticQuery\Aggregation\LeafAggregationCollection) {
6566
$array[$this->key()]['aggregations'][$aggregation->key()] = $aggregation->toArray()[$aggregation->key()];
6667

67-
} else {
68+
} elseif ($hasFilter) {
6869
$array[$this->key()]['aggregations'][$aggregation->key()] = $aggregation->toArray();
70+
71+
} else {
72+
$array[$this->key()] = $aggregation->toArray();
6973
}
7074
}
7175

72-
if ($this->filter) {
76+
if ($hasFilter) {
7377
$array[$this->key()]['filter'] = $this->filter->toArray();
7478
}
7579

0 commit comments

Comments
 (0)