| 1 | <?php |
||
| 22 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html |
||
| 23 | */ |
||
| 24 | class ChildrenAggregation extends AbstractAggregation |
||
| 25 | { |
||
| 26 | use BucketingTrait; |
||
| 27 | |||
| 28 | public function __construct(private string $name, private ?string $children = null) |
||
|
|
|||
| 29 | { |
||
| 30 | parent::__construct($name); |
||
| 31 | |||
| 32 | $this->setChildren($children); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function getChildren(): ?string |
||
| 36 | { |
||
| 37 | return $this->children; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function setChildren(?string $children): static |
||
| 41 | { |
||
| 42 | $this->children = $children; |
||
| 43 | |||
| 44 | return $this; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getType(): string |
||
| 48 | { |
||
| 49 | return 'children'; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function getArray(): array |
||
| 53 | { |
||
| 54 | if (count($this->getAggregations()) == 0) { |
||
| 55 | throw new \LogicException("Children aggregation `{$this->getName()}` has no aggregations added"); |
||
| 56 | } |
||
| 57 | |||
| 58 | return ['type' => $this->getChildren()]; |
||
| 59 | } |
||
| 60 | } |
||
| 61 |