Return buckets from an ES aggregation.

@param array $rawAggregations ES aggregations.

@return \Magento\Framework\Search\Response\Bucket[]
192476
private function getBuckets($rawAggregations)
    {
        $buckets = [];

        foreach ($rawAggregations as $bucketName => $rawBucket) {
            while (isset($rawBucket[$bucketName])) {
                $rawBucket = $rawBucket[$bucketName];
            }

            $bucketParams = ['name' => $bucketName, 'values' => $this->getBucketValues($rawBucket)];
            $buckets[$bucketName] = $this->bucketFactory->create($bucketParams);
        }

        return $buckets;
    }
61218
public function raw(array $attributes = [])
    {
        if ($this->amount === null) {
            return $this->getRawAttributes($attributes);
        }

        if ($this->amount < 1) {
            return [];
        }

        return array_map(function () use ($attributes) {
            return $this->getRawAttributes($attributes);
        }, range(1, $this->amount));
    }
360921
protected function getAllTypes(array $scopes)/*# : array */
    {
        $result = [];
        foreach ($scopes as $scope) {
            if ($this->isAType($scope)) {
                $result[] = $scope;
            }
        }
        return $result;
    }
411592
protected function buildSelectFromAggregation(Aggregation $aggregation)
    {
        $tableAlias = $this->getAlias();
        $rawColumns = $aggregation->getFields();
        $newSelect = $this->getLookupBuilder()->buildJoin($this, $rawColumns);
        if (false === $newSelect) {
            if (empty($tableAlias) || '*' === $rawColumns) {
                $columns = $rawColumns;
            } else {
                $columns = $tableAlias.'.'.$rawColumns;
            }
        } else {
            list($alias, $joinColumn) = $newSelect;
            $columns = $alias.'.'.$joinColumn;
        }
        $fieldsSql = $this->buildColumns($columns);
        $aggregation->setFieldsSql($fieldsSql);

        return $this->getAdapter()->quoteSql($aggregation->toSQL());
    }
1179286
public function toArray(): array
    {
        $result = [
            $this->type => $this->script ? ['script' => $this->script] : array_merge(['field' => $this->field], $this->additionalParams),
        ];

        if ($this->subAggregations) {
            $result['aggs'] = $this->subAggregations;
        }

        return $result;
    }
1077938
public function getAggregationTags(EntityDefinition $definition, Criteria $criteria, Aggregation $aggregation): array
    {
        $tags = [$definition->getEntityName() . '.id'];

        $fields = $criteria->getAggregationQueryFields();
        $fields = array_merge($fields, $aggregation->getFields());

        foreach ($fields as $accessor) {
            foreach ($this->getFieldsOfAccessor($definition, $accessor) as $association) {
                $tags[] = $association;
            }
        }

        return $tags;
    }
422573
public function assertionsFromRawCliConfig(array $rawAssertions)
    {
        $assertions = [];

        foreach ($rawAssertions as $rawAssertion) {
            $config = $this->jsonDecoder->decode($rawAssertion);
            $assertions[] = new AssertionMetadata($config);
        }

        return $assertions;
    }
707407
private function processAggregates($aggregates)
    {
        // Step 1. Calculate the aggregate group values.
        foreach ($this->collectionCursor as $model) {
            foreach ($aggregates as $aggregate) {
                $aggregate->calculateByIteration($model, $this->getGroupKeyForModel($model));
            }
        }

        $additionalData = [];

        // Step 2. Extract the group values and apply to models using augmentation data.
        foreach ($aggregates as $aggregate) {
            $groups = $aggregate->getGroups();

            foreach ($this->collectionCursor as $model) {
                $id = $model->UniqueIdentifier;
                $groupKey = $this->getGroupKeyForModel($model);

                if (!isset($additionalData[$id])) {
                    $additionalData[$id] = [];
                }

                if (isset($groups[$groupKey])) {
                    $additionalData[$id][$aggregate->getAlias()] = $groups[$groupKey];
                }
            }
        }

        // Give the cursor the augmentation data.
        $this->collectionCursor->setAugmentationData($additionalData);
    }
1168793
private function getSubAggregations($rawValue)
    {
        $subAggregations = [];

        foreach ($rawValue as $key => $value) {
            if (is_array($value)) {
                while (is_array($value) && isset($value[$key]) && is_array($value[$key])) {
                    $value = $value[$key];
                }

                if (isset($value['buckets'])) {
                    $subAggregations[$key] = $value;
                }
            }
        }

        return $this->create($subAggregations);
    }
72071
private function getConversionRateAggregation()
    {
        return $this->aggregationFactory->create(
            BucketInterface::TYPE_QUERY_GROUP,
            [
                'queries' => [
                    'sales' => $this->queryFactory->create(QueryInterface::TYPE_EXISTS, ['field' => 'product_sale']),
                ],
                'name' => 'conversion',
            ]
        );
    }
1332563
public function addAggregation(AbstractAggregation $abstractAggregation)
    {
        if (!$this->aggregations) {
            $this->aggregations = $this->createBuilderBag();
        }

        $this->aggregations->add($abstractAggregation);
        
        return $this;
    }
733355
private function prepareAggregations(array $searchResponse, AggregationFactory $aggregationFactory)
    {
        $aggregations = [];

        if (isset($searchResponse['aggregations'])) {
            $aggregations = $searchResponse['aggregations'];
        }

        $this->aggregations = $aggregationFactory->create($aggregations);
    }
234381
public function toArray(): array
    {
        return array_filter([
            'aggregations' => array_map(function (Aggregation $aggregation) {
                return $aggregation->toArray();
            }, $this->getAggregations()),
            'total_elements' => $this->getTotalElements(),
        ]);
    }
348909
func getAggregations(request *restful.Request) ([]core.AggregationType, error) {
	aggregationsRaw := strings.Split(request.PathParameter("aggregations"), ",")
	if len(aggregationsRaw) == 0 {
		return nil, fmt.Errorf("No aggregations specified")
	}

	aggregations := make([]core.AggregationType, len(aggregationsRaw))

	for ind, aggNameRaw := range aggregationsRaw {
		aggName := core.AggregationType(aggNameRaw)
		if _, ok := core.AllAggregations[aggName]; !ok {
			return nil, fmt.Errorf("Unknown aggregation %q", aggName)
		}
		aggregations[ind] = aggName
	}

	return aggregations, nil
}
122563
public function callAggregateCoreMetrics()
    {
        $this->logAggregator->setQueryOriginHint('Core');

        if ($this->shouldAggregateFromRawData) {
            $metrics = $this->aggregateDayVisitsMetrics();
        } else {
            $metrics = $this->aggregateMultipleVisitsMetrics();
        }

        if (empty($metrics)) {
            return array(
                'nb_visits' => false,
                'nb_visits_converted' => false
            );
        }
        return array(
            'nb_visits' => $metrics['nb_visits'],
            'nb_visits_converted' => $metrics['nb_visits_converted']
        );
    }
869688
public function toArray(): array
    {
        $response = [
            'from' => $this->from,
            'size' => $this->size,
        ];

        if ($this->sort) {
            $response['sort'] = $this->sort;
        }

        return [
            'bucket_sort' => $response
        ];
    }
413430
public function getBuckets()
    {
        if (!isset($this->rawData['buckets'])) {
            return null;
        }

        $buckets = [];

        foreach ($this->rawData['buckets'] as $bucket) {
            $buckets[] = new self($bucket);
        }

        return $buckets;
    }