Search in sources :

Example 11 with InternalAggregation

use of org.elasticsearch.search.aggregations.InternalAggregation in project elasticsearch by elastic.

the class InternalGeoCentroid method doReduce.

@Override
public InternalGeoCentroid doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    double lonSum = Double.NaN;
    double latSum = Double.NaN;
    int totalCount = 0;
    for (InternalAggregation aggregation : aggregations) {
        InternalGeoCentroid centroidAgg = (InternalGeoCentroid) aggregation;
        if (centroidAgg.count > 0) {
            totalCount += centroidAgg.count;
            if (Double.isNaN(lonSum)) {
                lonSum = centroidAgg.count * centroidAgg.centroid.getLon();
                latSum = centroidAgg.count * centroidAgg.centroid.getLat();
            } else {
                lonSum += (centroidAgg.count * centroidAgg.centroid.getLon());
                latSum += (centroidAgg.count * centroidAgg.centroid.getLat());
            }
        }
    }
    final GeoPoint result = (Double.isNaN(lonSum)) ? null : new GeoPoint(latSum / totalCount, lonSum / totalCount);
    return new InternalGeoCentroid(name, result, totalCount, pipelineAggregators(), getMetaData());
}
Also used : InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 12 with InternalAggregation

use of org.elasticsearch.search.aggregations.InternalAggregation in project elasticsearch by elastic.

the class SearchModule method registerAggregation.

private void registerAggregation(AggregationSpec spec) {
    if (false == transportClient) {
        namedXContents.add(new NamedXContentRegistry.Entry(BaseAggregationBuilder.class, spec.getName(), (p, c) -> {
            AggregatorFactories.AggParseContext context = (AggregatorFactories.AggParseContext) c;
            return spec.getParser().parse(context.name, context.queryParseContext);
        }));
    }
    namedWriteables.add(new NamedWriteableRegistry.Entry(AggregationBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
    for (Map.Entry<String, Writeable.Reader<? extends InternalAggregation>> t : spec.getResultReaders().entrySet()) {
        String writeableName = t.getKey();
        Writeable.Reader<? extends InternalAggregation> internalReader = t.getValue();
        namedWriteables.add(new NamedWriteableRegistry.Entry(InternalAggregation.class, writeableName, internalReader));
    }
}
Also used : InternalReverseNested(org.elasticsearch.search.aggregations.bucket.nested.InternalReverseNested) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) NestedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder) DerivativePipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregationBuilder) SumBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregationBuilder) UnmappedSampler(org.elasticsearch.search.aggregations.bucket.sampler.UnmappedSampler) RangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder) SumAggregationBuilder(org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder) HasParentQueryBuilder(org.elasticsearch.index.query.HasParentQueryBuilder) LongTerms(org.elasticsearch.search.aggregations.bucket.terms.LongTerms) InternalGeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.InternalGeoBounds) FieldValueFactorFunctionBuilder(org.elasticsearch.index.query.functionscore.FieldValueFactorFunctionBuilder) Map(java.util.Map) SuggesterSpec(org.elasticsearch.plugins.SearchPlugin.SuggesterSpec) ExtendedStatsBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregationBuilder) InternalExtendedStatsBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.InternalExtendedStatsBucket) SignificanceHeuristicParser(org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser) MutualInformation(org.elasticsearch.search.aggregations.bucket.significant.heuristics.MutualInformation) InternalDerivative(org.elasticsearch.search.aggregations.pipeline.derivative.InternalDerivative) InternalGeoDistance(org.elasticsearch.search.aggregations.bucket.range.geodistance.InternalGeoDistance) NamedRegistry(org.elasticsearch.common.NamedRegistry) ScriptScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder) InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) MaxAggregationBuilder(org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder) RandomScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.RandomScoreFunctionBuilder) FastVectorHighlighter(org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter) GeoDistanceQueryBuilder(org.elasticsearch.index.query.GeoDistanceQueryBuilder) QueryRescorerBuilder(org.elasticsearch.search.rescore.QueryRescorerBuilder) TermSuggestionBuilder(org.elasticsearch.search.suggest.term.TermSuggestionBuilder) SearchPlugin(org.elasticsearch.plugins.SearchPlugin) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder) CumulativeSumPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregationBuilder) SearchRequest(org.elasticsearch.action.search.SearchRequest) InternalFilter(org.elasticsearch.search.aggregations.bucket.filter.InternalFilter) SamplerAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder) MinBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) AggregatorFactories(org.elasticsearch.search.aggregations.AggregatorFactories) FetchPhaseConstructionContext(org.elasticsearch.plugins.SearchPlugin.FetchPhaseConstructionContext) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) MaxBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregator) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) GeoBoundingBoxQueryBuilder(org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder) VersionFetchSubPhase(org.elasticsearch.search.fetch.subphase.VersionFetchSubPhase) WildcardQueryBuilder(org.elasticsearch.index.query.WildcardQueryBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) DateHistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) InternalTopHits(org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHits) InternalCardinality(org.elasticsearch.search.aggregations.metrics.cardinality.InternalCardinality) GND(org.elasticsearch.search.aggregations.bucket.significant.heuristics.GND) WeightBuilder(org.elasticsearch.index.query.functionscore.WeightBuilder) InternalMax(org.elasticsearch.search.aggregations.metrics.max.InternalMax) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) MinBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregationBuilder) Settings(org.elasticsearch.common.settings.Settings) ParentIdQueryBuilder(org.elasticsearch.index.query.ParentIdQueryBuilder) LinearModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.LinearModel) FieldMaskingSpanQueryBuilder(org.elasticsearch.index.query.FieldMaskingSpanQueryBuilder) CompletionSuggestionBuilder(org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder) BucketScriptPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator) GeoBoundsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregationBuilder) ExponentialDecayFunctionBuilder(org.elasticsearch.index.query.functionscore.ExponentialDecayFunctionBuilder) BucketSelectorPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregator) InternalPercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.InternalPercentilesBucket) LinearDecayFunctionBuilder(org.elasticsearch.index.query.functionscore.LinearDecayFunctionBuilder) InternalHDRPercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentileRanks) GeoShapeQueryBuilder(org.elasticsearch.index.query.GeoShapeQueryBuilder) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) AvgBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregationBuilder) QueryParseContext(org.elasticsearch.index.query.QueryParseContext) ShapeBuilders(org.elasticsearch.common.geo.builders.ShapeBuilders) ReverseNestedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder) ScriptQueryBuilder(org.elasticsearch.index.query.ScriptQueryBuilder) TopHitsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregationBuilder) ExplainFetchSubPhase(org.elasticsearch.search.fetch.subphase.ExplainFetchSubPhase) BaseAggregationBuilder(org.elasticsearch.search.aggregations.BaseAggregationBuilder) PercentilesBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregationBuilder) DocValueFieldsFetchSubPhase(org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase) FetchPhase(org.elasticsearch.search.fetch.FetchPhase) MovAvgPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator) Laplace(org.elasticsearch.search.suggest.phrase.Laplace) InternalDateRange(org.elasticsearch.search.aggregations.bucket.range.date.InternalDateRange) SimpleModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel) QuerySpec(org.elasticsearch.plugins.SearchPlugin.QuerySpec) HighlightPhase(org.elasticsearch.search.fetch.subphase.highlight.HighlightPhase) Function(java.util.function.Function) PercentilesBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator) UnifiedHighlighter(org.elasticsearch.search.fetch.subphase.highlight.UnifiedHighlighter) InternalRange(org.elasticsearch.search.aggregations.bucket.range.InternalRange) StringTerms(org.elasticsearch.search.aggregations.bucket.terms.StringTerms) SpanOrQueryBuilder(org.elasticsearch.index.query.SpanOrQueryBuilder) MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) StatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuilder) FiltersAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder) PipelineAggregator(org.elasticsearch.search.aggregations.pipeline.PipelineAggregator) InternalExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats) InternalAvg(org.elasticsearch.search.aggregations.metrics.avg.InternalAvg) SearchExtensionSpec(org.elasticsearch.plugins.SearchPlugin.SearchExtensionSpec) PipelineAggregationSpec(org.elasticsearch.plugins.SearchPlugin.PipelineAggregationSpec) HistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder) FetchSourceSubPhase(org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) Consumer(java.util.function.Consumer) SearchExtSpec(org.elasticsearch.plugins.SearchPlugin.SearchExtSpec) HasChildQueryBuilder(org.elasticsearch.index.query.HasChildQueryBuilder) BucketSelectorPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregationBuilder) DoubleTerms(org.elasticsearch.search.aggregations.bucket.terms.DoubleTerms) Entry(org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry) ScoreFunctionSpec(org.elasticsearch.plugins.SearchPlugin.ScoreFunctionSpec) JLHScore(org.elasticsearch.search.aggregations.bucket.significant.heuristics.JLHScore) GaussDecayFunctionBuilder(org.elasticsearch.index.query.functionscore.GaussDecayFunctionBuilder) IpRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.ip.IpRangeAggregationBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) PlainHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PlainHighlighter) InternalNested(org.elasticsearch.search.aggregations.bucket.nested.InternalNested) MovAvgModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel) ChildrenAggregationBuilder(org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregationBuilder) EwmaModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.EwmaModel) InternalStatsBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.InternalStatsBucket) CardinalityAggregationBuilder(org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregationBuilder) SuggestionBuilder(org.elasticsearch.search.suggest.SuggestionBuilder) InternalValueCount(org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount) InternalSum(org.elasticsearch.search.aggregations.metrics.sum.InternalSum) SpanFirstQueryBuilder(org.elasticsearch.index.query.SpanFirstQueryBuilder) SpanTermQueryBuilder(org.elasticsearch.index.query.SpanTermQueryBuilder) SumBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator) GeoGridAggregationBuilder(org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder) CumulativeSumPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregator) StupidBackoff(org.elasticsearch.search.suggest.phrase.StupidBackoff) InternalGlobal(org.elasticsearch.search.aggregations.bucket.global.InternalGlobal) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) TypeQueryBuilder(org.elasticsearch.index.query.TypeQueryBuilder) LinearInterpolation(org.elasticsearch.search.suggest.phrase.LinearInterpolation) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) SpanContainingQueryBuilder(org.elasticsearch.index.query.SpanContainingQueryBuilder) ParseFieldRegistry(org.elasticsearch.common.xcontent.ParseFieldRegistry) DiversifiedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedAggregationBuilder) ExistsQueryBuilder(org.elasticsearch.index.query.ExistsQueryBuilder) NestedQueryBuilder(org.elasticsearch.index.query.NestedQueryBuilder) InternalGeoCentroid(org.elasticsearch.search.aggregations.metrics.geocentroid.InternalGeoCentroid) StatsBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregator) WrapperQueryBuilder(org.elasticsearch.index.query.WrapperQueryBuilder) HoltLinearModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltLinearModel) GeoCentroidAggregationBuilder(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregationBuilder) InternalSimpleValue(org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue) MatchPhraseQueryBuilder(org.elasticsearch.index.query.MatchPhraseQueryBuilder) InternalSampler(org.elasticsearch.search.aggregations.bucket.sampler.InternalSampler) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) InternalAdjacencyMatrix(org.elasticsearch.search.aggregations.bucket.adjacency.InternalAdjacencyMatrix) StatsBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregationBuilder) SimpleQueryStringBuilder(org.elasticsearch.index.query.SimpleQueryStringBuilder) ConstantScoreQueryBuilder(org.elasticsearch.index.query.ConstantScoreQueryBuilder) AvgBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregator) SerialDiffPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregationBuilder) RegexpQueryBuilder(org.elasticsearch.index.query.RegexpQueryBuilder) PercentageScore(org.elasticsearch.search.aggregations.bucket.significant.heuristics.PercentageScore) InternalStats(org.elasticsearch.search.aggregations.metrics.stats.InternalStats) SpanNearQueryBuilder(org.elasticsearch.index.query.SpanNearQueryBuilder) ArrayList(java.util.ArrayList) InternalChildren(org.elasticsearch.search.aggregations.bucket.children.InternalChildren) BiConsumer(java.util.function.BiConsumer) ExtendedStatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder) MaxBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregationBuilder) SortBuilder(org.elasticsearch.search.sort.SortBuilder) SignificanceHeuristic(org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) InternalHDRPercentiles(org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentiles) ParentFieldSubFetchPhase(org.elasticsearch.search.fetch.subphase.ParentFieldSubFetchPhase) MatchNoneQueryBuilder(org.elasticsearch.index.query.MatchNoneQueryBuilder) GlobalAggregationBuilder(org.elasticsearch.search.aggregations.bucket.global.GlobalAggregationBuilder) InternalDateHistogram(org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram) SpanMultiTermQueryBuilder(org.elasticsearch.index.query.SpanMultiTermQueryBuilder) ShapesAvailability(org.elasticsearch.common.geo.ShapesAvailability) GeoPolygonQueryBuilder(org.elasticsearch.index.query.GeoPolygonQueryBuilder) Highlighter(org.elasticsearch.search.fetch.subphase.highlight.Highlighter) PostingsHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PostingsHighlighter) SmoothingModel(org.elasticsearch.search.suggest.phrase.SmoothingModel) BoostingQueryBuilder(org.elasticsearch.index.query.BoostingQueryBuilder) InternalScriptedMetric(org.elasticsearch.search.aggregations.metrics.scripted.InternalScriptedMetric) GeoDistanceAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceAggregationBuilder) ExtendedStatsBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator) BucketScriptPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregationBuilder) InternalHistogram(org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram) ScriptSortBuilder(org.elasticsearch.search.sort.ScriptSortBuilder) PipelineAggregationBuilder(org.elasticsearch.search.aggregations.PipelineAggregationBuilder) PrefixQueryBuilder(org.elasticsearch.index.query.PrefixQueryBuilder) RescoreBuilder(org.elasticsearch.search.rescore.RescoreBuilder) InternalMin(org.elasticsearch.search.aggregations.metrics.min.InternalMin) MatchPhrasePrefixQueryBuilder(org.elasticsearch.index.query.MatchPhrasePrefixQueryBuilder) SignificantStringTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantStringTerms) PercentileRanksAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregationBuilder) ScriptFieldsFetchSubPhase(org.elasticsearch.search.fetch.subphase.ScriptFieldsFetchSubPhase) SearchResponse(org.elasticsearch.action.search.SearchResponse) MinAggregationBuilder(org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder) SpanWithinQueryBuilder(org.elasticsearch.index.query.SpanWithinQueryBuilder) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) MissingAggregationBuilder(org.elasticsearch.search.aggregations.bucket.missing.MissingAggregationBuilder) Setting(org.elasticsearch.common.settings.Setting) MatchedQueriesFetchSubPhase(org.elasticsearch.search.fetch.subphase.MatchedQueriesFetchSubPhase) InternalTDigestPercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentileRanks) InternalBucketMetricValue(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue) HoltWintersModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltWintersModel) ScoreSortBuilder(org.elasticsearch.search.sort.ScoreSortBuilder) ScriptedMetricAggregationBuilder(org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregationBuilder) SerialDiffPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator) List(java.util.List) UnmappedSignificantTerms(org.elasticsearch.search.aggregations.bucket.significant.UnmappedSignificantTerms) ChiSquare(org.elasticsearch.search.aggregations.bucket.significant.heuristics.ChiSquare) ValueCountAggregationBuilder(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregationBuilder) ScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) InternalGeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid) UnmappedTerms(org.elasticsearch.search.aggregations.bucket.terms.UnmappedTerms) AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) ExtendedStatsBucketParser(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketParser) SpanNotQueryBuilder(org.elasticsearch.index.query.SpanNotQueryBuilder) DateRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder) DerivativePipelineAggregator(org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator) FetchSubPhase(org.elasticsearch.search.fetch.FetchSubPhase) PercentilesAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesAggregationBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) Objects.requireNonNull(java.util.Objects.requireNonNull) AdjacencyMatrixAggregationBuilder(org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder) InternalMissing(org.elasticsearch.search.aggregations.bucket.missing.InternalMissing) InternalBinaryRange(org.elasticsearch.search.aggregations.bucket.range.InternalBinaryRange) MovAvgPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder) SignificantLongTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) AvgAggregationBuilder(org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder) PhraseSuggestionBuilder(org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder) AggregationSpec(org.elasticsearch.plugins.SearchPlugin.AggregationSpec) BooleanQuery(org.apache.lucene.search.BooleanQuery) InternalFilters(org.elasticsearch.search.aggregations.bucket.filters.InternalFilters) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) InternalTDigestPercentiles(org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentiles) Writeable(org.elasticsearch.common.io.stream.Writeable) ScriptHeuristic(org.elasticsearch.search.aggregations.bucket.significant.heuristics.ScriptHeuristic) FuzzyQueryBuilder(org.elasticsearch.index.query.FuzzyQueryBuilder) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NestedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder) DerivativePipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregationBuilder) SumBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregationBuilder) RangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder) SumAggregationBuilder(org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder) ExtendedStatsBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregationBuilder) MaxAggregationBuilder(org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder) CumulativeSumPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregationBuilder) SamplerAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) DateHistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) MinBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregationBuilder) GeoBoundsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregationBuilder) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) AvgBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregationBuilder) ReverseNestedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder) TopHitsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregationBuilder) BaseAggregationBuilder(org.elasticsearch.search.aggregations.BaseAggregationBuilder) PercentilesBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregationBuilder) StatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuilder) FiltersAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder) HistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder) BucketSelectorPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregationBuilder) IpRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.ip.IpRangeAggregationBuilder) ChildrenAggregationBuilder(org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregationBuilder) CardinalityAggregationBuilder(org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregationBuilder) GeoGridAggregationBuilder(org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder) DiversifiedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedAggregationBuilder) GeoCentroidAggregationBuilder(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregationBuilder) StatsBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregationBuilder) SerialDiffPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregationBuilder) ExtendedStatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder) MaxBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregationBuilder) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) GlobalAggregationBuilder(org.elasticsearch.search.aggregations.bucket.global.GlobalAggregationBuilder) GeoDistanceAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceAggregationBuilder) BucketScriptPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregationBuilder) PipelineAggregationBuilder(org.elasticsearch.search.aggregations.PipelineAggregationBuilder) PercentileRanksAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregationBuilder) MinAggregationBuilder(org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder) MissingAggregationBuilder(org.elasticsearch.search.aggregations.bucket.missing.MissingAggregationBuilder) ScriptedMetricAggregationBuilder(org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregationBuilder) ValueCountAggregationBuilder(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregationBuilder) AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) DateRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder) PercentilesAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesAggregationBuilder) AdjacencyMatrixAggregationBuilder(org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder) MovAvgPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder) AvgAggregationBuilder(org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder) Entry(org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry) InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) AggregatorFactories(org.elasticsearch.search.aggregations.AggregatorFactories) Writeable(org.elasticsearch.common.io.stream.Writeable) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Map(java.util.Map) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) BaseAggregationBuilder(org.elasticsearch.search.aggregations.BaseAggregationBuilder)

Example 13 with InternalAggregation

use of org.elasticsearch.search.aggregations.InternalAggregation in project elasticsearch by elastic.

the class InternalDateHistogram method reduceBuckets.

private List<Bucket> reduceBuckets(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    final PriorityQueue<IteratorAndCurrent> pq = new PriorityQueue<IteratorAndCurrent>(aggregations.size()) {

        @Override
        protected boolean lessThan(IteratorAndCurrent a, IteratorAndCurrent b) {
            return a.current.key < b.current.key;
        }
    };
    for (InternalAggregation aggregation : aggregations) {
        InternalDateHistogram histogram = (InternalDateHistogram) aggregation;
        if (histogram.buckets.isEmpty() == false) {
            pq.add(new IteratorAndCurrent(histogram.buckets.iterator()));
        }
    }
    List<Bucket> reducedBuckets = new ArrayList<>();
    if (pq.size() > 0) {
        // list of buckets coming from different shards that have the same key
        List<Bucket> currentBuckets = new ArrayList<>();
        double key = pq.top().current.key;
        do {
            final IteratorAndCurrent top = pq.top();
            if (top.current.key != key) {
                // the key changes, reduce what we already buffered and reset the buffer for current buckets
                final Bucket reduced = currentBuckets.get(0).reduce(currentBuckets, reduceContext);
                if (reduced.getDocCount() >= minDocCount || reduceContext.isFinalReduce() == false) {
                    reducedBuckets.add(reduced);
                }
                currentBuckets.clear();
                key = top.current.key;
            }
            currentBuckets.add(top.current);
            if (top.iterator.hasNext()) {
                final Bucket next = top.iterator.next();
                assert next.key > top.current.key : "shards must return data sorted by key";
                top.current = next;
                pq.updateTop();
            } else {
                pq.pop();
            }
        } while (pq.size() > 0);
        if (currentBuckets.isEmpty() == false) {
            final Bucket reduced = currentBuckets.get(0).reduce(currentBuckets, reduceContext);
            if (reduced.getDocCount() >= minDocCount || reduceContext.isFinalReduce() == false) {
                reducedBuckets.add(reduced);
            }
        }
    }
    return reducedBuckets;
}
Also used : InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) ArrayList(java.util.ArrayList) PriorityQueue(org.apache.lucene.util.PriorityQueue)

Example 14 with InternalAggregation

use of org.elasticsearch.search.aggregations.InternalAggregation in project elasticsearch by elastic.

the class InternalFilters method doReduce.

@Override
public InternalAggregation doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
    List<List<InternalBucket>> bucketsList = null;
    for (InternalAggregation aggregation : aggregations) {
        InternalFilters filters = (InternalFilters) aggregation;
        if (bucketsList == null) {
            bucketsList = new ArrayList<>(filters.buckets.size());
            for (InternalBucket bucket : filters.buckets) {
                List<InternalBucket> sameRangeList = new ArrayList<>(aggregations.size());
                sameRangeList.add(bucket);
                bucketsList.add(sameRangeList);
            }
        } else {
            int i = 0;
            for (InternalBucket bucket : filters.buckets) {
                bucketsList.get(i++).add(bucket);
            }
        }
    }
    InternalFilters reduced = new InternalFilters(name, new ArrayList<InternalBucket>(bucketsList.size()), keyed, pipelineAggregators(), getMetaData());
    for (List<InternalBucket> sameRangeList : bucketsList) {
        reduced.buckets.add((sameRangeList.get(0)).reduce(sameRangeList, reduceContext));
    }
    return reduced;
}
Also used : InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with InternalAggregation

use of org.elasticsearch.search.aggregations.InternalAggregation in project elasticsearch by elastic.

the class SearchPhaseController method reduceAggs.

private InternalAggregations reduceAggs(List<InternalAggregations> aggregationsList, List<SiblingPipelineAggregator> pipelineAggregators, ReduceContext reduceContext) {
    InternalAggregations aggregations = InternalAggregations.reduce(aggregationsList, reduceContext);
    if (pipelineAggregators != null) {
        List<InternalAggregation> newAggs = StreamSupport.stream(aggregations.spliterator(), false).map((p) -> (InternalAggregation) p).collect(Collectors.toList());
        for (SiblingPipelineAggregator pipelineAggregator : pipelineAggregators) {
            InternalAggregation newAgg = pipelineAggregator.doReduce(new InternalAggregations(newAggs), reduceContext);
            newAggs.add(newAgg);
        }
        return new InternalAggregations(newAggs);
    }
    return aggregations;
}
Also used : Arrays(java.util.Arrays) HppcMaps(org.elasticsearch.common.collect.HppcMaps) ScoreDoc(org.apache.lucene.search.ScoreDoc) Suggest(org.elasticsearch.search.suggest.Suggest) SearchHits(org.elasticsearch.search.SearchHits) BigArrays(org.elasticsearch.common.util.BigArrays) Term(org.apache.lucene.index.Term) ObjectObjectHashMap(com.carrotsearch.hppc.ObjectObjectHashMap) HashMap(java.util.HashMap) FieldDoc(org.apache.lucene.search.FieldDoc) Lucene(org.elasticsearch.common.lucene.Lucene) QuerySearchResultProvider(org.elasticsearch.search.query.QuerySearchResultProvider) ArrayList(java.util.ArrayList) Settings(org.elasticsearch.common.settings.Settings) FetchSearchResult(org.elasticsearch.search.fetch.FetchSearchResult) CollapseTopFieldDocs(org.apache.lucene.search.grouping.CollapseTopFieldDocs) IntArrayList(com.carrotsearch.hppc.IntArrayList) InternalAggregations(org.elasticsearch.search.aggregations.InternalAggregations) Map(java.util.Map) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) AggregatedDfs(org.elasticsearch.search.dfs.AggregatedDfs) StreamSupport(java.util.stream.StreamSupport) SortField(org.apache.lucene.search.SortField) Entry(org.elasticsearch.search.suggest.Suggest.Suggestion.Entry) TermStatistics(org.apache.lucene.search.TermStatistics) SearchHit(org.elasticsearch.search.SearchHit) CompletionSuggestion(org.elasticsearch.search.suggest.completion.CompletionSuggestion) TopDocs(org.apache.lucene.search.TopDocs) InternalSearchResponse(org.elasticsearch.search.internal.InternalSearchResponse) Suggestion(org.elasticsearch.search.suggest.Suggest.Suggestion) AbstractComponent(org.elasticsearch.common.component.AbstractComponent) Sort(org.apache.lucene.search.Sort) AtomicArray(org.elasticsearch.common.util.concurrent.AtomicArray) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) DfsSearchResult(org.elasticsearch.search.dfs.DfsSearchResult) InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) ReduceContext(org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext) CollectionStatistics(org.apache.lucene.search.CollectionStatistics) List(java.util.List) QuerySearchResult(org.elasticsearch.search.query.QuerySearchResult) SiblingPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator) TopFieldDocs(org.apache.lucene.search.TopFieldDocs) SearchProfileShardResults(org.elasticsearch.search.profile.SearchProfileShardResults) ScriptService(org.elasticsearch.script.ScriptService) Collections(java.util.Collections) InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) InternalAggregations(org.elasticsearch.search.aggregations.InternalAggregations) SiblingPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator)

Aggregations

InternalAggregation (org.elasticsearch.search.aggregations.InternalAggregation)33 ArrayList (java.util.ArrayList)23 List (java.util.List)16 Map (java.util.Map)10 InternalAggregations (org.elasticsearch.search.aggregations.InternalAggregations)10 IOException (java.io.IOException)8 Collectors (java.util.stream.Collectors)8 PipelineAggregator (org.elasticsearch.search.aggregations.pipeline.PipelineAggregator)8 StreamSupport (java.util.stream.StreamSupport)7 StreamInput (org.elasticsearch.common.io.stream.StreamInput)7 ReduceContext (org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext)7 Bucket (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket)7 InternalSimpleValue (org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue)6 HashMap (java.util.HashMap)5 DocValueFormat (org.elasticsearch.search.DocValueFormat)5 StreamOutput (org.elasticsearch.common.io.stream.StreamOutput)4 Settings (org.elasticsearch.common.settings.Settings)4 SignificanceHeuristic (org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic)4 GapPolicy (org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy)4 BucketHelpers.resolveBucketValue (org.elasticsearch.search.aggregations.pipeline.BucketHelpers.resolveBucketValue)4