Skip to content

Commit 2214fd1

Browse files
committed
Added Filter aggregation
1 parent 90b0fee commit 2214fd1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Aggregation/Filter.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\ElasticQuery\Aggregation;
4+
5+
/**
6+
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
7+
*/
8+
class Filter extends \Spameri\ElasticQuery\Filter\FilterCollection
9+
implements \Spameri\ElasticQuery\Aggregation\LeafAggregationInterface
10+
{
11+
12+
public function toArray(): array
13+
{
14+
$array = parent::toArray();
15+
16+
if ($array === []) {
17+
$array['must'] = [];
18+
}
19+
20+
return [
21+
'filter' => [
22+
'bool' => $array,
23+
],
24+
];
25+
}
26+
27+
}

0 commit comments

Comments
 (0)