Skip to content

Commit 90b0fee

Browse files
committed
Added AVG aggregation
1 parent 55b4925 commit 90b0fee

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/Aggregation/Avg.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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-metrics-avg-aggregation.html
7+
*/
8+
class Avg implements \Spameri\ElasticQuery\Aggregation\LeafAggregationInterface
9+
{
10+
11+
private string $field;
12+
13+
14+
public function __construct(
15+
string $field
16+
)
17+
{
18+
$this->field = $field;
19+
}
20+
21+
22+
public function key(): string
23+
{
24+
return 'avg_' . $this->field;
25+
}
26+
27+
28+
public function toArray(): array
29+
{
30+
return [
31+
'avg' => [
32+
'field' => $this->field,
33+
],
34+
];
35+
}
36+
37+
}

0 commit comments

Comments
 (0)