Skip to content

Commit

Permalink
Merge pull request #153 from tchiotludo/bugfix/innerhit
Browse files Browse the repository at this point in the history
InnerHit query is optional
  • Loading branch information
saimaz committed Sep 8, 2016
2 parents 43c1006 + a61fb0d commit e84c380
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/InnerHit/NestedInnerHit.php
Expand Up @@ -48,7 +48,7 @@ class NestedInnerHit implements BuilderInterface
* @param string $path
* @param BuilderInterface $query
*/
public function __construct($name, $path, BuilderInterface $query)
public function __construct($name, $path, BuilderInterface $query = null)
{
$this->setName($name);
$this->setPath($path);
Expand Down Expand Up @@ -82,7 +82,7 @@ public function getQuery()
/**
* @param BuilderInterface $query
*/
public function setQuery(BuilderInterface $query)
public function setQuery(BuilderInterface $query = null)
{
$this->query = $query;
}
Expand Down Expand Up @@ -145,14 +145,16 @@ public function toArray()
{
$out = array_filter(
[
'query' => $this->getQuery()->toArray(),
'query' => $this->getQuery() ? $this->getQuery()->toArray() : null,
'inner_hits' => $this->collectNestedInnerHits(),
]
);

$out = $this->processArray($out);

$out = [
$this->getPathType() => [
$this->getPath() => $this->processArray($out),
$this->getPath() => $out ? $out : new \stdClass(),
],
];

Expand Down

0 comments on commit e84c380

Please sign in to comment.