public function buildAggregations(array $buckets = [])
{
$aggregations = [];
foreach ($buckets as $bucket) {
$bucketType = $bucket->getType();
$builder = $this->getBuilder($bucketType);
$aggregation = $builder->buildBucket($bucket);
if ($bucket->isNested()) {
if ($bucket->getNestedFilter()) {
$aggregation = ['filter' => $this->queryBuilder->buildQuery($bucket->getNestedFilter()), 'aggregations' => [$bucket->getName() => $aggregation]];
}
$aggregation = ['nested' => ['path' => $bucket->getNestedPath()], 'aggregations' => [$bucket->getName() => $aggregation]];
}
if ($bucket->getFilter()) {
$aggregation = ['filter' => $this->queryBuilder->buildQuery($bucket->getFilter()), 'aggregations' => [$bucket->getName() => $aggregation]];
}
$aggregations[$bucket->getName()] = $aggregation;
}
return $aggregations;
}