From 8d6710fd2619e72552ac9690a750f40a6577d0da Mon Sep 17 00:00:00 2001 From: tchiotludo <tchiot.ludo@gmail.com> Date: Wed, 7 Sep 2016 18:09:19 +0200 Subject: [PATCH] InnerHit query is optional --- src/InnerHit/NestedInnerHit.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/InnerHit/NestedInnerHit.php b/src/InnerHit/NestedInnerHit.php index 73dc853..fb9a8d4 100644 --- a/src/InnerHit/NestedInnerHit.php +++ b/src/InnerHit/NestedInnerHit.php @@ -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); @@ -82,7 +82,7 @@ class NestedInnerHit implements BuilderInterface /** * @param BuilderInterface $query */ - public function setQuery(BuilderInterface $query) + public function setQuery(BuilderInterface $query = null) { $this->query = $query; } @@ -145,14 +145,16 @@ class NestedInnerHit implements BuilderInterface { $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(), ], ]; -- GitLab