Closed irongomme closed 3 years ago
I've found how to use aggregation. So if it can be usefull, here is my way :
// Declare aggregations
$filtersAggs = new \Elastica\Aggregation\Terms('filters');
$filtersAggs->setField('filters.filter_value_id');
$filtersAggs->setSize(100);
$printersAggs = new \Elastica\Aggregation\Terms('printers');
$printersAggs->setField('printers.keyword');
$printersAggs->setSize(50);
// Add it to query
$results = $this->EsProducts->find()
->where($conditions)
->limit($limit)
->page($page)
->aggregate([$filtersAggs, $printersAggs])
->all();
// Read results
$totalCount = $results->getTotalHits();
$filterAggregation = $results->getAggregation('filters');
$printerAggregation = `$results->getAggregation('printers');
Is it possible to have a sample use for aggregation ?