Build the aggregation.

@param BucketInterface $bucket Histogram bucket.

@return array
760315
public function buildBucket(BucketInterface $bucket)
    {
        if ($bucket->getType() !== BucketInterface::TYPE_DATE_HISTOGRAM) {
            throw new \InvalidArgumentException("Query builder : invalid aggregation type {$bucket->getType()}.");
        }

        $aggParams = [
            'field'         => $bucket->getField(),
            'interval'      => $bucket->getInterval(),
            'min_doc_count' => $bucket->getMinDocCount(),
        ];

        return ['date_histogram' => $aggParams];
    }
473176
protected function save($bucket) {
        return $this->storage->set($this->key, json_encode($bucket->getData()));
    }
451578
public static function stat($bucketName, $path) {
        $path = self::normalizerPath($path);

        return self::statBase($bucketName, $path);
    }
606208
public function listBuckets()
    {
        $buckets = [];

        $response = $this->client->request('POST', $this->apiUrl.'/b2_list_buckets', [
            'headers' => [
                'Authorization' => $this->authToken,
            ],
            'json' => [
                'accountId' => $this->accountId
            ]
        ]);

        foreach ($response['buckets'] as $bucket) {
            $buckets[] = new Bucket($bucket['bucketId'], $bucket['bucketName'], $bucket['bucketType']);
        }

        return $buckets;
    }
1152582
private function getS3Bucket()
    {
        $settings = $this->getSettings();

        $bucket = S3Bucket::getInstance(
            $settings->bucketRegion,
            $settings->bucketName,
            $settings->awsKey,
            $settings->awsSecret
        );

        return $bucket;
    }
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;
    }
64083
protected function createArray(string $fieldName, array $aggregation): array
    {
        $return = [];
        $buckets = $aggregation['buckets'] ?? $aggregation[$fieldName]['buckets'] ?? null;
        if (!$buckets) {
            return $return;
        }
        $attributeId = $this->isAttribute($fieldName);
        foreach ($buckets as $key => $bucket) {
            $return[$key]['count'] = $bucket['doc_count'];
            $return[$key][($attributeId === false ? $fieldName : 'attributeValueId')] = $bucket['key'];
            if ($attributeId !== false) {
                $return[$key]['attributeId'] = $attributeId;
            }
        }

        return array_values($return);
    }
186794
public static function statFolder($bucketName, $path)
    {
        $path = self::normalizerPath($path, true);

        return self::statBase($bucketName, $path);
    }
494957
public function bucketDestroy($bucket)
    {
        $oBucket = $this->getBucket($bucket);

        if (!$oBucket) {
            $this->setError('Not a valid bucket');
            return false;
        }

        // --------------------------------------------------------------------------

        //  Destroy any containing objects
        $errors = 0;
        foreach ($oBucket->objects as $obj) {
            if (!$this->objectDestroy($obj->id)) {
                $this->setError('Unable to delete object "' . $obj->file->name->human . '" (ID:' . $obj->id . ').');
                $errors++;
            }
        }

        if ($errors) {

            $this->setError('Unable to delete bucket, bucket not empty.');
            return false;

        } else {

            if ($this->callDriver('bucketDestroy', [$oBucket->slug])) {

                $oDb = Factory::service('Database');
                $oDb->where('id', $oBucket->id);
                $oDb->delete(NAILS_DB_PREFIX . 'cdn_bucket');
                return true;

            } else {

                $this->setError('Unable to remove empty bucket directory. ' . $this->callDriver('lastError'));
                return false;
            }
        }
    }
869688
public function toArray(): array
    {
        $response = [
            'from' => $this->from,
            'size' => $this->size,
        ];

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

        return [
            'bucket_sort' => $response
        ];
    }
149970
private function getAggregations(RequestInterface $request)
    {
        $aggregations = [];

        if ($request->getAggregation()) {
            $aggregations = $this->aggregationBuilder->buildAggregations($request->getAggregation());
        }

        return $aggregations;
    }
683062
public function build(): GetHistogramsRequest
	{
		$instance = new GetHistogramsRequest();
		$instance->query = $this->query;
		$instance->delta = $this->delta;
		return $instance;
	}
372821
public function count($bucket){
        $amount = 0;
        $flag = true;
        $marker = '';
        while ($flag){
            $response = $this->listFiles($bucket, 1000, '', $marker);
            if(!$response['success']){
                return $response;
            }
            $marker = isset($response['data']['marker']) ? $response['data']['marker'] : '';
            $items = $response['data']['items'];
            $amount += count($items);
            if(!$marker){
                $flag = false;
            }
        }
        return $this->success('操作成功', ['amount'=>$amount]);
    }
677597
public static function statFolder($bucketName, $path) {
        $path = self::normalizerPath($path, True);	

        return self::statBase($bucketName, $path);
    }
1341566
public function buildIndex($bucketName, $indexNames)
    {
        $indexNames = is_array($indexNames) ? $indexNames : [$indexNames];

        foreach ($indexNames as $i => $indexName) {
            $indexNames[$i] = $this->db->quoteColumnName($indexName);
        }

        return 'BUILD INDEX ' . $this->db->quoteBucketName($bucketName) . '(' . implode(', ', $indexNames) . ') USING GSI';
    }
463990
public function groupBy($expression) : Stage\BucketAuto
    {
        assert($this->bucket instanceof Stage\BucketAuto);
        return $this->bucket->groupBy($expression);
    }
1177129
public function listBuckets()
    {
        $buckets = [];

        $response = $this->generateAuthenticatedClient([
            'accountId' => $this->accountId,
        ])->request('POST', '/b2_list_buckets');

        foreach ($response['buckets'] as $bucket) {
            $buckets[] = new Bucket($bucket['bucketId'], $bucket['bucketName'], $bucket['bucketType']);
        }

        return $buckets;
    }