setFilter($filter); } } /** * Set the filter for this aggregation. * * @param AbstractQuery $filter * * @return $this */ public function setFilter(AbstractQuery $filter) { return $this->setParam('filter', $filter); } /** * @throws \Elastica\Exception\InvalidException If filter is not set * * @return array */ public function toArray(): array { if (!$this->hasParam('filter')) { throw new InvalidException('Filter is required'); } $array = [ 'filter' => $this->getParam('filter')->toArray(), ]; if ($this->_aggs) { $array['aggs'] = $this->_convertArrayable($this->_aggs); } return $array; } }