/** * Add a sub-aggregation * @throws \Elastica\Exception\InvalidException * * @param AbstractAggregation $aggregation * @return $this */ public function addAggregation(AbstractAggregation $aggregation) { if ($aggregation instanceof GlobalAggregation) { throw new InvalidException('Global aggregators can only be placed as top level aggregators'); } $this->_aggs[$aggregation->getName()] = $aggregation->toArray(); return $this; }
/** * Adds an Aggregation to the query * * @param AbstractAggregation $agg * @return \Elastica\Query Query object */ public function addAggregation(AbstractAggregation $agg) { if (!array_key_exists('aggs', $this->_params)) { $this->_params['aggs'] = array(); } $this->_params['aggs'][$agg->getName()] = $agg->toArray(); return $this; }