| 1 | <?php |
||
| 23 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html |
||
| 24 | */ |
||
| 25 | class StatsAggregation extends AbstractAggregation |
||
| 26 | { |
||
| 27 | use MetricTrait; |
||
| 28 | |||
| 29 | use ScriptAwareTrait; |
||
| 30 | |||
| 31 | public function __construct( |
||
| 32 | private string $name, |
||
|
|
|||
| 33 | private ?string $field = null, |
||
| 34 | ?string $script = null |
||
| 35 | ) { |
||
| 36 | parent::__construct($name); |
||
| 37 | |||
| 38 | $this->setField($field); |
||
| 39 | $this->setScript($script); |
||
| 40 | } |
||
| 41 | |||
| 42 | public function getType(): string |
||
| 43 | { |
||
| 44 | return 'stats'; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getArray(): array |
||
| 48 | { |
||
| 49 | $out = []; |
||
| 50 | |||
| 51 | if ($this->getField()) { |
||
| 52 | $out['field'] = $this->getField(); |
||
| 53 | } |
||
| 54 | |||
| 55 | if ($this->getScript()) { |
||
| 56 | $out['script'] = $this->getScript(); |
||
| 57 | } |
||
| 58 | |||
| 59 | return $out; |
||
| 60 | } |
||
| 61 | } |
||
| 62 |