| 1 | <?php |
||
| 11 | |||
| 12 | declare(strict_types=1); |
||
| 13 | |||
| 14 | namespace ONGR\ElasticsearchDSL\Query\Joining; |
||
| 15 | |||
| 16 | use ONGR\ElasticsearchDSL\BuilderInterface; |
||
| 17 | use ONGR\ElasticsearchDSL\ParametersTrait; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-parent-id-query.html |
||
| 21 | */ |
||
| 22 | class ParentIdQuery implements BuilderInterface |
||
| 23 | { |
||
| 24 | use ParametersTrait; |
||
| 25 | |||
| 26 | public function __construct( |
||
| 27 | private string $parentId, |
||
|
|
|||
| 28 | private string $childType, |
||
| 29 | array $parameters = [] |
||
| 30 | ) { |
||
| 31 | $this->setParameters($parameters); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function getType(): string |
||
| 35 | { |
||
| 36 | return 'parent_id'; |
||
| 37 | } |
||
| 38 | |||
| 39 | public function toArray(): array |
||
| 40 | { |
||
| 41 | $query = [ |
||
| 42 | 'id' => $this->parentId, |
||
| 43 | 'type' => $this->childType, |
||
| 44 | ]; |
||
| 45 | $output = $this->processArray($query); |
||
| 46 | |||
| 47 | return [$this->getType() => $output]; |
||
| 48 | } |
||
| 49 | } |
||
| 50 |