Skip to content

Commit 0a81a23

Browse files
committed
Add ValueCount aggregation
1 parent 65ecc26 commit 0a81a23

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Aggregation/Aggregation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,9 @@ public static function stats(string $name): StatsAggregation
130130
{
131131
return new StatsAggregation($name);
132132
}
133+
134+
public static function valueCount(string $name, string $field, array $aggregations = []): ValueCountAggregation
135+
{
136+
return new ValueCountAggregation($name, $field, $aggregations);
137+
}
133138
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Erichard\ElasticQueryBuilder\Aggregation;
4+
5+
use Erichard\ElasticQueryBuilder\Options\Field;
6+
use Erichard\ElasticQueryBuilder\Options\SourceScript;
7+
8+
9+
class ValueCountAggregation extends MetricAggregation
10+
{
11+
public function __construct(
12+
string $nameAndField,
13+
Field|SourceScript|string|null $fieldOrSource = null,
14+
array $aggregations = []
15+
) {
16+
parent::__construct($nameAndField, $fieldOrSource, $aggregations);
17+
}
18+
19+
protected function getType(): string
20+
{
21+
return 'value_count';
22+
}
23+
24+
protected function buildAggregation(): array
25+
{
26+
$build = parent::buildAggregation();
27+
28+
return $build;
29+
}
30+
}

0 commit comments

Comments
 (0)