ElasticsearchDSL
ElasticsearchDSL copied to clipboard
Add support for Parent Id Query
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-parent-id-query.html
<?php
namespace ONGR\ElasticsearchDSL\Query\Joining;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-parent-id-query.html
*/
class ParentIdQuery implements BuilderInterface
{
use ParametersTrait;
/**
* @var string
*/
private $childType;
/**
* @var string
*/
private $parentId;
/**
* @param string $parentId
* @param string $childType
* @param array $parameters
*/
public function __construct($parentId, string $childType, array $parameters = [])
{
$this->childType = $childType;
$this->parentId = $parentId;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'parent_id';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [
'id' => $this->parentId,
'type' => $this->childType,
];
$output = $this->processArray($query);
return [$this->getType() => $output];
}
}
Here is some working code for parent_id quey, sry that i didn't made a PR, feels bad. (It will also work if you put this class into your own bundle and use it there, just change the namespace to your own)
Thanks for the input @oliver-schulz