/** * @param Terms $termsAgg * @throws ErrorException */ private function addAggregation(Terms $termsAgg) { foreach ($this->aggregation as $parameter => $queryAttr) { $aggregationModel = new Aggregation(); $aggregationModel->parameter = $parameter; $aggregationModel->attributes = $queryAttr; $itemAgg = $aggregationModel->getElasticaAggregations(); $itemAgg->setField($parameter); $termsAgg->addAggregation($itemAgg); $this->aggregationList[] = ['type' => $aggregationModel->type, 'index' => $aggregationModel->getAggregationName(), 'title' => (string) $aggregationModel]; } }