parseStatsAggregation example

Context $context
    ): void {
        match (true) {
            $aggregation instanceof DateHistogramAggregation => $this->parseDateHistogramAggregation($aggregation$query$definition$context),
            $aggregation instanceof TermsAggregation => $this->parseTermsAggregation($aggregation$query$definition$context),
            $aggregation instanceof FilterAggregation => $this->parseFilterAggregation($aggregation$query$definition$context),
            $aggregation instanceof AvgAggregation => $this->parseAvgAggregation($aggregation$query$definition$context),
            $aggregation instanceof SumAggregation => $this->parseSumAggregation($aggregation$query$definition$context),
            $aggregation instanceof MaxAggregation => $this->parseMaxAggregation($aggregation$query$definition$context),
            $aggregation instanceof MinAggregation => $this->parseMinAggregation($aggregation$query$definition$context),
            $aggregation instanceof CountAggregation => $this->parseCountAggregation($aggregation$query$definition$context),
            $aggregation instanceof StatsAggregation => $this->parseStatsAggregation($aggregation$query$definition$context),
            $aggregation instanceof EntityAggregation => $this->parseEntityAggregation($aggregation$query$definition$context),
            $aggregation instanceof RangeAggregation => $this->parseRangeAggregation($aggregation$query$definition$context),
            default => throw new InvalidAggregationQueryException(sprintf('Aggregation of type %s not supported', $aggregation::class)),
        };
    }

    private function parseFilterAggregation(
        FilterAggregation $aggregation,
        QueryBuilder $query,
        EntityDefinition $definition,
        Context $context
    ):
private function createAggregation(Aggregation $aggregation, string $fieldName, EntityDefinition $definition, Context $context): AbstractAggregation
    {
        if ($this->keyValueStorage->get(ElasticsearchIndexer::ENABLE_MULTILINGUAL_INDEX_KEY, false)) {
            $field = $this->getField($definition$fieldName);

            if ($field instanceof TranslatedField) {
                $fieldName = $this->getTranslatedFieldName($fieldName$context->getLanguageId());
            }
        }

        return match (true) {
            $aggregation instanceof StatsAggregation => $this->parseStatsAggregation($aggregation$fieldName$context),
            $aggregation instanceof AvgAggregation => new Metric\AvgAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof EntityAggregation => $this->parseEntityAggregation($aggregation$fieldName),
            $aggregation instanceof MaxAggregation => new Metric\MaxAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof MinAggregation => new Metric\MinAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof SumAggregation => new Metric\SumAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof CountAggregation => new ValueCountAggregation($aggregation->getName()$fieldName),
            $aggregation instanceof FilterAggregation => $this->parseFilterAggregation($aggregation$definition$context),
            $aggregation instanceof TermsAggregation => $this->parseTermsAggregation($aggregation$fieldName$definition$context),
            $aggregation instanceof DateHistogramAggregation => $this->parseDateHistogramAggregation($aggregation$fieldName$definition$context),
            $aggregation instanceof RangeAggregation => $this->parseRangeAggregation($aggregation$fieldName),
            default => throw new \RuntimeException(sprintf('Provided aggregation of class %s not supported', $aggregation::class)),
        };
Home | Imprint | This part of the site doesn't use cookies.