1 | <?php |
||
23 | class ExtendedStatsAggregation extends AbstractAggregation |
||
24 | { |
||
25 | use MetricTrait; |
||
26 | |||
27 | use ScriptAwareTrait; |
||
28 | |||
29 | public function __construct( |
||
30 | private string $name, |
||
|
|||
31 | private ?string $field = null, |
||
32 | private ?int $sigma = null, |
||
33 | private ?string $script = null |
||
34 | ) { |
||
35 | parent::__construct($name); |
||
36 | |||
37 | $this->setField($field); |
||
38 | $this->setSigma($sigma); |
||
39 | $this->setScript($script); |
||
40 | } |
||
41 | |||
42 | public function getSigma(): ?int |
||
43 | { |
||
44 | return $this->sigma; |
||
45 | } |
||
46 | |||
47 | public function setSigma(?int $sigma): static |
||
48 | { |
||
49 | $this->sigma = $sigma; |
||
50 | |||
51 | return $this; |
||
52 | } |
||
53 | |||
54 | public function getType(): string |
||
55 | { |
||
56 | return 'extended_stats'; |
||
57 | } |
||
58 | |||
59 | public function getArray(): array |
||
60 | { |
||
61 | return array_filter( |
||
62 | [ |
||
63 | 'field' => $this->getField(), |
||
64 | 'script' => $this->getScript(), |
||
65 | 'sigma' => $this->getSigma(), |
||
66 | ], |
||
67 | fn(mixed $val): bool => $val || is_numeric($val) |
||
68 | ); |
||
69 | } |
||
70 | } |
||
71 |