hasParam('filters') && \count($this->getParam('filters')) && $this->_type !== $type ) { throw new InvalidException('Mix named and anonymous keys are not allowed'); } $this->_type = $type; return $this->addParam('filters', $filterArray); } /** * @param bool $otherBucket * * @return $this */ public function setOtherBucket(bool $otherBucket): self { return $this->setParam('other_bucket', $otherBucket); } /** * @param string $otherBucketKey * * @return $this */ public function setOtherBucketKey(string $otherBucketKey): self { return $this->setParam('other_bucket_key', $otherBucketKey); } /** * @return array */ public function toArray(): array { $array = []; $filters = $this->getParam('filters'); foreach ($filters as $filter) { if (self::NAMED_TYPE === $this->_type) { $key = \key($filter); $array['filters']['filters'][$key] = \current($filter)->toArray(); } else { $array['filters']['filters'][] = \current($filter)->toArray(); } } if ($this->hasParam('other_bucket')) { $array['filters']['other_bucket'] = $this->getParam('other_bucket'); } if ($this->hasParam('other_bucket_key')) { $array['filters']['other_bucket_key'] = $this->getParam('other_bucket_key'); } if ($this->_aggs) { $array['aggs'] = $this->_convertArrayable($this->_aggs); } return $array; } }