-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathChildrenAggregation.php
58 lines (46 loc) · 1.37 KB
/
ChildrenAggregation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ONGR\ElasticsearchDSL\Aggregation\Bucketing;
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
/**
* Class representing ChildrenAggregation.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html
*/
class ChildrenAggregation extends AbstractAggregation
{
use BucketingTrait;
public function __construct(private string $name, private ?string $children = null)
{
parent::__construct($name);
}
public function getChildren(): ?string
{
return $this->children;
}
public function setChildren(?string $children): static
{
$this->children = $children;
return $this;
}
public function getType(): string
{
return 'children';
}
public function getArray(): array
{
if (count($this->getAggregations()) == 0) {
throw new \LogicException("Children aggregation `{$this->getName()}` has no aggregations added");
}
return ['type' => $this->getChildren()];
}
}