From ebc745211d454fcaddde90159d75c44aeecf6f3e Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Mon, 15 Feb 2016 12:49:39 +0000 Subject: [PATCH] Moved AggregatorBuilder implementations into their own class files Also renamed histogram.AbstractBuilcer to AbstractHistogramBuilder, range.AbstractBuilder to AbstractRangeBuilder and org.elasticsearch.search.aggregations.pipeline.having to org.elasticsearch.search.aggregations.pipeline.bucketselector --- .../elasticsearch/search/SearchModule.java | 4 +- .../aggregations/AggregationBuilders.java | 50 +- .../children/ChildrenAggregatorBuilder.java | 132 ++++ .../bucket/children/ChildrenParser.java | 8 +- .../children/ParentToChildrenAggregator.java | 106 --- .../bucket/filter/FilterAggregator.java | 68 -- .../filter/FilterAggregatorBuilder.java | 93 +++ .../bucket/filter/FilterParser.java | 8 +- .../bucket/filters/FiltersAggregator.java | 165 ----- .../filters/FiltersAggregatorBuilder.java | 198 ++++++ .../bucket/filters/FiltersParser.java | 12 +- .../geogrid/GeoGridAggregatorBuilder.java | 221 ++++++ .../bucket/geogrid/GeoHashGridAggregator.java | 4 +- .../geogrid/GeoHashGridAggregatorFactory.java | 9 +- .../bucket/geogrid/GeoHashGridParser.java | 196 ------ .../bucket/global/GlobalAggregator.java | 49 -- .../global/GlobalAggregatorBuilder.java | 73 ++ .../bucket/global/GlobalParser.java | 8 +- .../histogram/AbstractHistogramBuilder.java | 211 ++++++ .../DateHistogramAggregatorBuilder.java | 129 ++++ .../bucket/histogram/DateHistogramParser.java | 5 +- .../bucket/histogram/HistogramAggregator.java | 309 --------- .../histogram/HistogramAggregatorBuilder.java | 50 ++ .../bucket/histogram/HistogramParser.java | 8 +- .../bucket/missing/MissingAggregator.java | 51 -- .../missing/MissingAggregatorBuilder.java | 76 +++ .../bucket/missing/MissingParser.java | 8 +- .../bucket/nested/NestedAggregator.java | 73 -- .../nested/NestedAggregatorBuilder.java | 97 +++ .../bucket/nested/NestedParser.java | 8 +- .../nested/ReverseNestedAggregator.java | 77 --- .../ReverseNestedAggregatorBuilder.java | 101 +++ .../bucket/nested/ReverseNestedParser.java | 8 +- .../bucket/range/AbstractRangeBuilder.java | 105 +++ .../bucket/range/RangeAggregator.java | 171 ----- .../bucket/range/RangeAggregatorBuilder.java | 122 ++++ .../bucket/range/RangeParser.java | 8 +- .../date/DateRangeAggregatorBuilder.java | 4 +- .../GeoDistanceAggregatorBuilder.java | 246 +++++++ .../range/geodistance/GeoDistanceParser.java | 218 +----- .../ipv4/IPv4RangeAggregatorBuilder.java | 4 +- .../sampler/DiversifiedAggregatorBuilder.java | 154 +++++ .../sampler/DiversifiedSamplerParser.java | 8 +- .../bucket/sampler/SamplerAggregator.java | 197 +----- .../sampler/SamplerAggregatorBuilder.java | 97 +++ .../bucket/sampler/SamplerParser.java | 8 +- .../metrics/avg/AvgAggregator.java | 51 -- .../metrics/avg/AvgAggregatorBuilder.java | 77 +++ .../aggregations/metrics/avg/AvgParser.java | 8 +- .../geobounds/GeoBoundsAggregator.java | 75 +- .../geobounds/GeoBoundsAggregatorBuilder.java | 97 +++ .../metrics/geobounds/GeoBoundsParser.java | 8 +- .../geocentroid/GeoCentroidAggregator.java | 52 +- .../GeoCentroidAggregatorBuilder.java | 78 +++ .../geocentroid/GeoCentroidParser.java | 8 +- .../metrics/max/MaxAggregator.java | 52 -- .../metrics/max/MaxAggregatorBuilder.java | 78 +++ .../aggregations/metrics/max/MaxParser.java | 8 +- .../metrics/min/MinAggregator.java | 51 -- .../metrics/min/MinAggregatorBuilder.java | 77 +++ .../aggregations/metrics/min/MinParser.java | 8 +- .../scripted/ScriptedMetricAggregator.java | 189 ----- .../ScriptedMetricAggregatorBuilder.java | 215 ++++++ .../scripted/ScriptedMetricParser.java | 8 +- .../metrics/stats/StatsAggregator.java | 51 -- .../metrics/stats/StatsAggregatorBuilder.java | 77 +++ .../metrics/stats/StatsParser.java | 6 +- .../extended/ExtendedStatsAggregator.java | 70 -- .../ExtendedStatsAggregatorBuilder.java | 96 +++ .../stats/extended/ExtendedStatsParser.java | 6 +- .../metrics/sum/SumAggregator.java | 51 -- .../metrics/sum/SumAggregatorBuilder.java | 76 +++ .../aggregations/metrics/sum/SumParser.java | 6 +- .../metrics/tophits/TopHitsAggregator.java | 620 +---------------- .../tophits/TopHitsAggregatorBuilder.java | 644 ++++++++++++++++++ .../metrics/tophits/TopHitsParser.java | 8 +- .../valuecount/ValueCountAggregator.java | 52 -- .../ValueCountAggregatorBuilder.java | 77 +++ .../metrics/valuecount/ValueCountParser.java | 8 +- .../pipeline/PipelineAggregatorBuilders.java | 86 +-- .../bucketmetrics/avg/AvgBucketParser.java | 8 +- .../avg/AvgBucketPipelineAggregator.java | 58 -- .../AvgBucketPipelineAggregatorBuilder.java | 85 +++ .../bucketmetrics/max/MaxBucketParser.java | 8 +- .../max/MaxBucketPipelineAggregator.java | 60 -- .../MaxBucketPipelineAggregatorBuilder.java | 87 +++ .../bucketmetrics/min/MinBucketParser.java | 8 +- .../min/MinBucketPipelineAggregator.java | 60 -- .../MinBucketPipelineAggregatorBuilder.java | 87 +++ .../percentile/PercentilesBucketParser.java | 10 +- .../PercentilesBucketPipelineAggregator.java | 100 --- ...ntilesBucketPipelineAggregatorBuilder.java | 128 ++++ .../stats/StatsBucketParser.java | 8 +- .../stats/StatsBucketPipelineAggregator.java | 60 -- .../StatsBucketPipelineAggregatorBuilder.java | 88 +++ .../extended/ExtendedStatsBucketParser.java | 10 +- ...ExtendedStatsBucketPipelineAggregator.java | 92 --- ...dStatsBucketPipelineAggregatorBuilder.java | 120 ++++ .../bucketmetrics/sum/SumBucketParser.java | 8 +- .../sum/SumBucketPipelineAggregator.java | 60 -- .../SumBucketPipelineAggregatorBuilder.java | 87 +++ .../bucketscript/BucketScriptParser.java | 10 +- .../BucketScriptPipelineAggregator.java | 138 ---- ...BucketScriptPipelineAggregatorBuilder.java | 170 +++++ .../BucketSelectorParser.java | 12 +- .../BucketSelectorPipelineAggregator.java | 114 +--- ...cketSelectorPipelineAggregatorBuilder.java | 139 ++++ .../cumulativesum/CumulativeSumParser.java | 10 +- .../CumulativeSumPipelineAggregator.java | 104 --- ...umulativeSumPipelineAggregatorBuilder.java | 133 ++++ .../pipeline/derivative/DerivativeParser.java | 10 +- .../DerivativePipelineAggregator.java | 170 ----- .../DerivativePipelineAggregatorBuilder.java | 200 ++++++ .../pipeline/movavg/MovAvgParser.java | 10 +- .../movavg/MovAvgPipelineAggregator.java | 270 -------- .../MovAvgPipelineAggregatorBuilder.java | 302 ++++++++ .../pipeline/serialdiff/SerialDiffParser.java | 10 +- .../SerialDiffPipelineAggregator.java | 127 ---- .../SerialDiffPipelineAggregatorBuilder.java | 156 +++++ .../aggregations/bucket/ChildrenTests.java | 5 +- .../bucket/DateHistogramTests.java | 2 +- .../bucket/DiversifiedSamplerIT.java | 2 +- .../bucket/DiversifiedSamplerTests.java | 8 +- .../bucket/GeoDistanceRangeTests.java | 2 +- .../aggregations/bucket/GeoHashGridTests.java | 2 +- .../aggregations/bucket/GlobalTests.java | 7 +- .../aggregations/bucket/HistogramTests.java | 5 +- .../aggregations/bucket/NaNSortingIT.java | 16 +- .../aggregations/bucket/RangeTests.java | 5 +- .../search/aggregations/bucket/SamplerIT.java | 9 +- .../aggregations/bucket/SamplerTests.java | 8 +- .../bucket/nested/NestedAggregatorTests.java | 2 +- .../bucket/nested/NestedTests.java | 3 +- .../bucket/nested/ReverseNestedTests.java | 3 +- .../search/aggregations/metrics/AvgTests.java | 8 +- .../metrics/ExtendedStatsTests.java | 8 +- .../aggregations/metrics/FilterTests.java | 5 +- .../aggregations/metrics/FiltersTests.java | 5 +- .../aggregations/metrics/GeoBoundsTests.java | 5 +- .../metrics/GeoCentroidTests.java | 5 +- .../search/aggregations/metrics/MaxTests.java | 8 +- .../search/aggregations/metrics/MinTests.java | 7 +- .../aggregations/metrics/MissingTests.java | 8 +- .../metrics/ScriptedMetricTests.java | 5 +- .../aggregations/metrics/StatsTests.java | 8 +- .../search/aggregations/metrics/SumTests.java | 8 +- .../aggregations/metrics/TopHitsTests.java | 8 +- .../aggregations/metrics/ValueCountTests.java | 8 +- .../pipeline/BucketScriptTests.java | 6 +- .../pipeline/BucketSelectorTests.java | 7 +- .../pipeline/CumulativeSumTests.java | 6 +- .../pipeline/DerivativeTests.java | 5 +- .../PipelineAggregationHelperTests.java | 16 +- .../pipeline/SerialDifferenceTests.java | 6 +- .../bucketmetrics/AvgBucketTests.java | 5 +- .../ExtendedStatsBucketTests.java | 11 +- .../bucketmetrics/MaxBucketTests.java | 5 +- .../bucketmetrics/MinBucketTests.java | 5 +- .../bucketmetrics/PercentilesBucketTests.java | 11 +- .../bucketmetrics/StatsBucketTests.java | 8 +- .../bucketmetrics/SumBucketTests.java | 5 +- .../pipeline/moving/avg/MovAvgTests.java | 5 +- .../messy/tests/EquivalenceTests.java | 4 +- 163 files changed, 5843 insertions(+), 4785 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ChildrenAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AbstractHistogramBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/{having => bucketselector}/BucketSelectorParser.java (90%) rename core/src/main/java/org/elasticsearch/search/aggregations/pipeline/{having => bucketselector}/BucketSelectorPipelineAggregator.java (52%) create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java create mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 702cd6eb9f2..62bfc1de856 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -192,13 +192,13 @@ import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucke import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptParser; import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorParser; +import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumParser; import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativeParser; import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.derivative.InternalDerivative; -import org.elasticsearch.search.aggregations.pipeline.having.BucketSelectorParser; -import org.elasticsearch.search.aggregations.pipeline.having.BucketSelectorPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser; import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilders.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilders.java index c4f477ef637..1da7c28cf09 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilders.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilders.java @@ -22,65 +22,65 @@ import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.aggregations.bucket.children.Children; -import org.elasticsearch.search.aggregations.bucket.children.ParentToChildrenAggregator.ChildrenAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.filter.Filter; -import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregator.FilterAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.filters.Filters; -import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.FiltersAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.KeyedFilter; +import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid; -import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridParser.GeoGridAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.global.Global; -import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator.GlobalAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; -import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator.DateHistogramAggregatorBuilder; -import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator.HistogramAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.missing.Missing; -import org.elasticsearch.search.aggregations.bucket.missing.MissingAggregator.MissingAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.missing.MissingAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.nested.Nested; -import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregator.NestedAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.nested.ReverseNested; -import org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregator.ReverseNestedAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.Range; -import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.RangeAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.range.RangeAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregatorBuilder; -import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceParser.GeoDistanceAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.ipv4.IPv4RangeAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.sampler.Sampler; -import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregator.DiversifiedAggregatorBuilder; -import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregator.SamplerAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.avg.Avg; -import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregator.AvgAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds; -import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregator.GeoBoundsAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid; -import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregator.GeoCentroidAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.max.Max; -import org.elasticsearch.search.aggregations.metrics.max.MaxAggregator.MaxAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.max.MaxAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.min.Min; -import org.elasticsearch.search.aggregations.metrics.min.MinAggregator.MinAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.min.MinAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles; import org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetric; -import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregator.ScriptedMetricAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.stats.Stats; -import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregator.StatsAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; -import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.sum.Sum; -import org.elasticsearch.search.aggregations.metrics.sum.SumAggregator.SumAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.sum.SumAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.tophits.TopHits; -import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregator.TopHitsAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount; -import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregator.ValueCountAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregatorBuilder; /** * Utility class to create aggregations. diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ChildrenAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ChildrenAggregatorBuilder.java new file mode 100644 index 00000000000..3f143e5e4e7 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ChildrenAggregatorBuilder.java @@ -0,0 +1,132 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.children; + +import org.apache.lucene.search.Query; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData; +import org.elasticsearch.index.mapper.DocumentMapper; +import org.elasticsearch.index.mapper.internal.ParentFieldMapper; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.FieldContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.ParentChild; + +import java.io.IOException; +import java.util.Objects; + +public class ChildrenAggregatorBuilder extends ValuesSourceAggregatorBuilder { + + static final ChildrenAggregatorBuilder PROTOTYPE = new ChildrenAggregatorBuilder("", ""); + + private String parentType; + private final String childType; + private Query parentFilter; + private Query childFilter; + + /** + * @param name + * the name of this aggregation + * @param childType + * the type of children documents + */ + public ChildrenAggregatorBuilder(String name, String childType) { + super(name, InternalChildren.TYPE, ValuesSourceType.BYTES, ValueType.STRING); + if (childType == null) { + throw new IllegalArgumentException("[childType] must not be null: [" + name + "]"); + } + this.childType = childType; + } + + @Override + protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, + ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new ChildrenAggregatorFactory(name, type, config, parentType, childFilter, parentFilter, context, parent, + subFactoriesBuilder, metaData); + } + + @Override + protected ValuesSourceConfig resolveConfig(AggregationContext aggregationContext) { + ValuesSourceConfig config = new ValuesSourceConfig<>(ValuesSourceType.BYTES); + DocumentMapper childDocMapper = aggregationContext.searchContext().mapperService().documentMapper(childType); + + if (childDocMapper != null) { + ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper(); + if (!parentFieldMapper.active()) { + throw new IllegalArgumentException("[children] no [_parent] field not configured that points to a parent type"); + } + parentType = parentFieldMapper.type(); + DocumentMapper parentDocMapper = aggregationContext.searchContext().mapperService().documentMapper(parentType); + if (parentDocMapper != null) { + parentFilter = parentDocMapper.typeFilter(); + childFilter = childDocMapper.typeFilter(); + ParentChildIndexFieldData parentChildIndexFieldData = aggregationContext.searchContext().fieldData() + .getForField(parentFieldMapper.fieldType()); + config.fieldContext(new FieldContext(parentFieldMapper.fieldType().name(), parentChildIndexFieldData, + parentFieldMapper.fieldType())); + } else { + config.unmapped(true); + } + } else { + config.unmapped(true); + } + return config; + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + builder.field(ParentToChildrenAggregator.TYPE_FIELD.getPreferredName(), childType); + return builder; + } + + @Override + protected ChildrenAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) throws IOException { + String childType = in.readString(); + ChildrenAggregatorBuilder factory = new ChildrenAggregatorBuilder(name, childType); + return factory; + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeString(childType); + } + + @Override + protected int innerHashCode() { + return Objects.hash(childType); + } + + @Override + protected boolean innerEquals(Object obj) { + ChildrenAggregatorBuilder other = (ChildrenAggregatorBuilder) obj; + return Objects.equals(childType, other.childType); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ChildrenParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ChildrenParser.java index 788532b1617..9c40c2f4a32 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ChildrenParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ChildrenParser.java @@ -35,7 +35,7 @@ public class ChildrenParser implements Aggregator.Parser { } @Override - public ParentToChildrenAggregator.ChildrenAggregatorBuilder parse(String aggregationName, XContentParser parser, + public ChildrenAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException { String childType = null; @@ -62,11 +62,11 @@ public class ChildrenParser implements Aggregator.Parser { } - return new ParentToChildrenAggregator.ChildrenAggregatorBuilder(aggregationName, childType); + return new ChildrenAggregatorBuilder(aggregationName, childType); } @Override - public ParentToChildrenAggregator.ChildrenAggregatorBuilder getFactoryPrototypes() { - return ParentToChildrenAggregator.ChildrenAggregatorBuilder.PROTOTYPE; + public ChildrenAggregatorBuilder getFactoryPrototypes() { + return ChildrenAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ParentToChildrenAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ParentToChildrenAggregator.java index 266c4ec0ba9..c844f968b9c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ParentToChildrenAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ParentToChildrenAggregator.java @@ -28,39 +28,23 @@ import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; import org.apache.lucene.util.Bits; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.LongObjectPagedHashMap; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData; -import org.elasticsearch.index.mapper.DocumentMapper; -import org.elasticsearch.index.mapper.internal.ParentFieldMapper; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.FieldContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.ParentChild; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.Objects; // The RecordingPerReaderBucketCollector assumes per segment recording which isn't the case for this // aggregation, for this reason that collector can't be used @@ -190,94 +174,4 @@ public class ParentToChildrenAggregator extends SingleBucketAggregator { protected void doClose() { Releasables.close(parentOrdToBuckets, parentOrdToOtherBuckets); } - - public static class ChildrenAggregatorBuilder extends ValuesSourceAggregatorBuilder { - - static final ChildrenAggregatorBuilder PROTOTYPE = new ChildrenAggregatorBuilder("", ""); - - private String parentType; - private final String childType; - private Query parentFilter; - private Query childFilter; - - /** - * @param name - * the name of this aggregation - * @param childType - * the type of children documents - */ - public ChildrenAggregatorBuilder(String name, String childType) { - super(name, InternalChildren.TYPE, ValuesSourceType.BYTES, ValueType.STRING); - if (childType == null) { - throw new IllegalArgumentException("[childType] must not be null: [" + name + "]"); - } - this.childType = childType; - } - - @Override - protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, - ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new ChildrenAggregatorFactory(name, type, config, parentType, childFilter, parentFilter, context, parent, - subFactoriesBuilder, metaData); - } - - @Override - protected ValuesSourceConfig resolveConfig(AggregationContext aggregationContext) { - ValuesSourceConfig config = new ValuesSourceConfig<>(ValuesSourceType.BYTES); - DocumentMapper childDocMapper = aggregationContext.searchContext().mapperService().documentMapper(childType); - - if (childDocMapper != null) { - ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper(); - if (!parentFieldMapper.active()) { - throw new IllegalArgumentException("[children] no [_parent] field not configured that points to a parent type"); - } - parentType = parentFieldMapper.type(); - DocumentMapper parentDocMapper = aggregationContext.searchContext().mapperService().documentMapper(parentType); - if (parentDocMapper != null) { - parentFilter = parentDocMapper.typeFilter(); - childFilter = childDocMapper.typeFilter(); - ParentChildIndexFieldData parentChildIndexFieldData = aggregationContext.searchContext().fieldData() - .getForField(parentFieldMapper.fieldType()); - config.fieldContext(new FieldContext(parentFieldMapper.fieldType().name(), parentChildIndexFieldData, - parentFieldMapper.fieldType())); - } else { - config.unmapped(true); - } - } else { - config.unmapped(true); - } - return config; - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.field(TYPE_FIELD.getPreferredName(), childType); - return builder; - } - - @Override - protected ChildrenAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - String childType = in.readString(); - ChildrenAggregatorBuilder factory = new ChildrenAggregatorBuilder(name, childType); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeString(childType); - } - - @Override - protected int innerHashCode() { - return Objects.hash(childType); - } - - @Override - protected boolean innerEquals(Object obj) { - ChildrenAggregatorBuilder other = (ChildrenAggregatorBuilder) obj; - return Objects.equals(childType, other.childType); - } - - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregator.java index e3c727554aa..1a79631f93d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregator.java @@ -21,16 +21,9 @@ package org.elasticsearch.search.aggregations.bucket.filter; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Weight; import org.apache.lucene.util.Bits; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.query.EmptyQueryBuilder; -import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; @@ -41,7 +34,6 @@ import org.elasticsearch.search.aggregations.support.AggregationContext; import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Objects; /** * Aggregate all docs that match a filter. @@ -85,66 +77,6 @@ public class FilterAggregator extends SingleBucketAggregator { public InternalAggregation buildEmptyAggregation() { return new InternalFilter(name, 0, buildEmptySubAggregations(), pipelineAggregators(), metaData()); } - - public static class FilterAggregatorBuilder extends AggregatorBuilder { - - static final FilterAggregatorBuilder PROTOTYPE = new FilterAggregatorBuilder("", EmptyQueryBuilder.PROTOTYPE); - - private final QueryBuilder filter; - - /** - * @param name - * the name of this aggregation - * @param filter - * Set the filter to use, only documents that match this - * filter will fall into the bucket defined by this - * {@link Filter} aggregation. - */ - public FilterAggregatorBuilder(String name, QueryBuilder filter) { - super(name, InternalFilter.TYPE); - if (filter == null) { - throw new IllegalArgumentException("[filter] must not be null: [" + name + "]"); - } - this.filter = filter; - } - - @Override - protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, - AggregatorFactories.Builder subFactoriesBuilder) throws IOException { - return new FilterAggregatorFactory(name, type, filter, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - if (filter != null) { - filter.toXContent(builder, params); - } - return builder; - } - - @Override - protected FilterAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { - FilterAggregatorBuilder factory = new FilterAggregatorBuilder(name, in.readQuery()); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeQuery(filter); - } - - @Override - protected int doHashCode() { - return Objects.hash(filter); - } - - @Override - protected boolean doEquals(Object obj) { - FilterAggregatorBuilder other = (FilterAggregatorBuilder) obj; - return Objects.equals(filter, other.filter); - } - - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregatorBuilder.java new file mode 100644 index 00000000000..88535e3021b --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregatorBuilder.java @@ -0,0 +1,93 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.filter; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.query.EmptyQueryBuilder; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.search.aggregations.AggregatorBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactories; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.support.AggregationContext; + +import java.io.IOException; +import java.util.Objects; + +public class FilterAggregatorBuilder extends AggregatorBuilder { + + static final FilterAggregatorBuilder PROTOTYPE = new FilterAggregatorBuilder("", EmptyQueryBuilder.PROTOTYPE); + + private final QueryBuilder filter; + + /** + * @param name + * the name of this aggregation + * @param filter + * Set the filter to use, only documents that match this + * filter will fall into the bucket defined by this + * {@link Filter} aggregation. + */ + public FilterAggregatorBuilder(String name, QueryBuilder filter) { + super(name, InternalFilter.TYPE); + if (filter == null) { + throw new IllegalArgumentException("[filter] must not be null: [" + name + "]"); + } + this.filter = filter; + } + + @Override + protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, + AggregatorFactories.Builder subFactoriesBuilder) throws IOException { + return new FilterAggregatorFactory(name, type, filter, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + if (filter != null) { + filter.toXContent(builder, params); + } + return builder; + } + + @Override + protected FilterAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { + FilterAggregatorBuilder factory = new FilterAggregatorBuilder(name, in.readQuery()); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeQuery(filter); + } + + @Override + protected int doHashCode() { + return Objects.hash(filter); + } + + @Override + protected boolean doEquals(Object obj) { + FilterAggregatorBuilder other = (FilterAggregatorBuilder) obj; + return Objects.equals(filter, other.filter); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterParser.java index 1ff3d9913a6..9047d31fe7e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterParser.java @@ -37,7 +37,7 @@ public class FilterParser implements Aggregator.Parser { } @Override - public FilterAggregator.FilterAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) + public FilterAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException { QueryBuilder filter = context.parseInnerQueryBuilder(); @@ -45,14 +45,14 @@ public class FilterParser implements Aggregator.Parser { throw new ParsingException(null, "filter cannot be null in filter aggregation [{}]", aggregationName); } - FilterAggregator.FilterAggregatorBuilder factory = new FilterAggregator.FilterAggregatorBuilder(aggregationName, + FilterAggregatorBuilder factory = new FilterAggregatorBuilder(aggregationName, filter == null ? new MatchAllQueryBuilder() : filter); return factory; } @Override - public FilterAggregator.FilterAggregatorBuilder getFactoryPrototypes() { - return FilterAggregator.FilterAggregatorBuilder.PROTOTYPE; + public FilterAggregatorBuilder getFactoryPrototypes() { + return FilterAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregator.java index 1593eeb2437..17a7ae4ebe5 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregator.java @@ -33,20 +33,16 @@ import org.elasticsearch.index.query.EmptyQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.bucket.BucketsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Objects; @@ -205,165 +201,4 @@ public class FiltersAggregator extends BucketsAggregator { return owningBucketOrdinal * totalNumKeys + filterOrd; } - public static class FiltersAggregatorBuilder extends AggregatorBuilder { - - static final FiltersAggregatorBuilder PROTOTYPE = new FiltersAggregatorBuilder("", EmptyQueryBuilder.PROTOTYPE); - - private final List filters; - private final boolean keyed; - private boolean otherBucket = false; - private String otherBucketKey = "_other_"; - - /** - * @param name - * the name of this aggregation - * @param filters - * the KeyedFilters to use with this aggregation. - */ - public FiltersAggregatorBuilder(String name, KeyedFilter... filters) { - this(name, Arrays.asList(filters)); - } - - private FiltersAggregatorBuilder(String name, List filters) { - super(name, InternalFilters.TYPE); - this.filters = filters; - this.keyed = true; - } - - /** - * @param name - * the name of this aggregation - * @param filters - * the filters to use with this aggregation - */ - public FiltersAggregatorBuilder(String name, QueryBuilder... filters) { - super(name, InternalFilters.TYPE); - List keyedFilters = new ArrayList<>(filters.length); - for (int i = 0; i < filters.length; i++) { - keyedFilters.add(new KeyedFilter(String.valueOf(i), filters[i])); - } - this.filters = keyedFilters; - this.keyed = false; - } - - /** - * Set whether to include a bucket for documents not matching any filter - */ - public FiltersAggregatorBuilder otherBucket(boolean otherBucket) { - this.otherBucket = otherBucket; - return this; - } - - /** - * Get whether to include a bucket for documents not matching any filter - */ - public boolean otherBucket() { - return otherBucket; - } - - /** - * Set the key to use for the bucket for documents not matching any - * filter. - */ - public FiltersAggregatorBuilder otherBucketKey(String otherBucketKey) { - if (otherBucketKey == null) { - throw new IllegalArgumentException("[otherBucketKey] must not be null: [" + name + "]"); - } - this.otherBucketKey = otherBucketKey; - return this; - } - - /** - * Get the key to use for the bucket for documents not matching any - * filter. - */ - public String otherBucketKey() { - return otherBucketKey; - } - - @Override - protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) - throws IOException { - return new FiltersAggregatorFactory(name, type, filters, keyed, otherBucket, otherBucketKey, context, parent, - subFactoriesBuilder, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - if (keyed) { - builder.startObject(FILTERS_FIELD.getPreferredName()); - for (KeyedFilter keyedFilter : filters) { - builder.field(keyedFilter.key(), keyedFilter.filter()); - } - builder.endObject(); - } else { - builder.startArray(FILTERS_FIELD.getPreferredName()); - for (KeyedFilter keyedFilter : filters) { - builder.value(keyedFilter.filter()); - } - builder.endArray(); - } - builder.field(OTHER_BUCKET_FIELD.getPreferredName(), otherBucket); - builder.field(OTHER_BUCKET_KEY_FIELD.getPreferredName(), otherBucketKey); - builder.endObject(); - return builder; - } - - @Override - protected FiltersAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { - FiltersAggregatorBuilder factory; - if (in.readBoolean()) { - int size = in.readVInt(); - List filters = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - filters.add(KeyedFilter.PROTOTYPE.readFrom(in)); - } - factory = new FiltersAggregatorBuilder(name, filters); - } else { - int size = in.readVInt(); - QueryBuilder[] filters = new QueryBuilder[size]; - for (int i = 0; i < size; i++) { - filters[i] = in.readQuery(); - } - factory = new FiltersAggregatorBuilder(name, filters); - } - factory.otherBucket = in.readBoolean(); - factory.otherBucketKey = in.readString(); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeBoolean(keyed); - if (keyed) { - out.writeVInt(filters.size()); - for (KeyedFilter keyedFilter : filters) { - keyedFilter.writeTo(out); - } - } else { - out.writeVInt(filters.size()); - for (KeyedFilter keyedFilter : filters) { - out.writeQuery(keyedFilter.filter()); - } - } - out.writeBoolean(otherBucket); - out.writeString(otherBucketKey); - } - - @Override - protected int doHashCode() { - return Objects.hash(filters, keyed, otherBucket, otherBucketKey); - } - - @Override - protected boolean doEquals(Object obj) { - FiltersAggregatorBuilder other = (FiltersAggregatorBuilder) obj; - return Objects.equals(filters, other.filters) - && Objects.equals(keyed, other.keyed) - && Objects.equals(otherBucket, other.otherBucket) - && Objects.equals(otherBucketKey, other.otherBucketKey); - } - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java new file mode 100644 index 00000000000..ad683e134e5 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java @@ -0,0 +1,198 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.filters; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.query.EmptyQueryBuilder; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.search.aggregations.AggregatorBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.KeyedFilter; +import org.elasticsearch.search.aggregations.support.AggregationContext; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +public class FiltersAggregatorBuilder extends AggregatorBuilder { + + static final FiltersAggregatorBuilder PROTOTYPE = new FiltersAggregatorBuilder("", EmptyQueryBuilder.PROTOTYPE); + + private final List filters; + private final boolean keyed; + private boolean otherBucket = false; + private String otherBucketKey = "_other_"; + + /** + * @param name + * the name of this aggregation + * @param filters + * the KeyedFilters to use with this aggregation. + */ + public FiltersAggregatorBuilder(String name, KeyedFilter... filters) { + this(name, Arrays.asList(filters)); + } + + private FiltersAggregatorBuilder(String name, List filters) { + super(name, InternalFilters.TYPE); + this.filters = filters; + this.keyed = true; + } + + /** + * @param name + * the name of this aggregation + * @param filters + * the filters to use with this aggregation + */ + public FiltersAggregatorBuilder(String name, QueryBuilder... filters) { + super(name, InternalFilters.TYPE); + List keyedFilters = new ArrayList<>(filters.length); + for (int i = 0; i < filters.length; i++) { + keyedFilters.add(new KeyedFilter(String.valueOf(i), filters[i])); + } + this.filters = keyedFilters; + this.keyed = false; + } + + /** + * Set whether to include a bucket for documents not matching any filter + */ + public FiltersAggregatorBuilder otherBucket(boolean otherBucket) { + this.otherBucket = otherBucket; + return this; + } + + /** + * Get whether to include a bucket for documents not matching any filter + */ + public boolean otherBucket() { + return otherBucket; + } + + /** + * Set the key to use for the bucket for documents not matching any + * filter. + */ + public FiltersAggregatorBuilder otherBucketKey(String otherBucketKey) { + if (otherBucketKey == null) { + throw new IllegalArgumentException("[otherBucketKey] must not be null: [" + name + "]"); + } + this.otherBucketKey = otherBucketKey; + return this; + } + + /** + * Get the key to use for the bucket for documents not matching any + * filter. + */ + public String otherBucketKey() { + return otherBucketKey; + } + + @Override + protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) + throws IOException { + return new FiltersAggregatorFactory(name, type, filters, keyed, otherBucket, otherBucketKey, context, parent, + subFactoriesBuilder, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + if (keyed) { + builder.startObject(FiltersAggregator.FILTERS_FIELD.getPreferredName()); + for (KeyedFilter keyedFilter : filters) { + builder.field(keyedFilter.key(), keyedFilter.filter()); + } + builder.endObject(); + } else { + builder.startArray(FiltersAggregator.FILTERS_FIELD.getPreferredName()); + for (KeyedFilter keyedFilter : filters) { + builder.value(keyedFilter.filter()); + } + builder.endArray(); + } + builder.field(FiltersAggregator.OTHER_BUCKET_FIELD.getPreferredName(), otherBucket); + builder.field(FiltersAggregator.OTHER_BUCKET_KEY_FIELD.getPreferredName(), otherBucketKey); + builder.endObject(); + return builder; + } + + @Override + protected FiltersAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { + FiltersAggregatorBuilder factory; + if (in.readBoolean()) { + int size = in.readVInt(); + List filters = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + filters.add(KeyedFilter.PROTOTYPE.readFrom(in)); + } + factory = new FiltersAggregatorBuilder(name, filters); + } else { + int size = in.readVInt(); + QueryBuilder[] filters = new QueryBuilder[size]; + for (int i = 0; i < size; i++) { + filters[i] = in.readQuery(); + } + factory = new FiltersAggregatorBuilder(name, filters); + } + factory.otherBucket = in.readBoolean(); + factory.otherBucketKey = in.readString(); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeBoolean(keyed); + if (keyed) { + out.writeVInt(filters.size()); + for (KeyedFilter keyedFilter : filters) { + keyedFilter.writeTo(out); + } + } else { + out.writeVInt(filters.size()); + for (KeyedFilter keyedFilter : filters) { + out.writeQuery(keyedFilter.filter()); + } + } + out.writeBoolean(otherBucket); + out.writeString(otherBucketKey); + } + + @Override + protected int doHashCode() { + return Objects.hash(filters, keyed, otherBucket, otherBucketKey); + } + + @Override + protected boolean doEquals(Object obj) { + FiltersAggregatorBuilder other = (FiltersAggregatorBuilder) obj; + return Objects.equals(filters, other.filters) + && Objects.equals(keyed, other.keyed) + && Objects.equals(otherBucket, other.otherBucket) + && Objects.equals(otherBucketKey, other.otherBucketKey); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersParser.java index e8fcf38ddcb..a3cd32a1cfe 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersParser.java @@ -53,7 +53,7 @@ public class FiltersParser implements Aggregator.Parser { } @Override - public FiltersAggregator.FiltersAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) + public FiltersAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException { List keyedFilters = null; @@ -124,12 +124,12 @@ public class FiltersParser implements Aggregator.Parser { otherBucketKey = "_other_"; } - FiltersAggregator.FiltersAggregatorBuilder factory; + FiltersAggregatorBuilder factory; if (keyedFilters != null) { - factory = new FiltersAggregator.FiltersAggregatorBuilder(aggregationName, + factory = new FiltersAggregatorBuilder(aggregationName, keyedFilters.toArray(new FiltersAggregator.KeyedFilter[keyedFilters.size()])); } else { - factory = new FiltersAggregator.FiltersAggregatorBuilder(aggregationName, + factory = new FiltersAggregatorBuilder(aggregationName, nonKeyedFilters.toArray(new QueryBuilder[nonKeyedFilters.size()])); } if (otherBucket != null) { @@ -142,8 +142,8 @@ public class FiltersParser implements Aggregator.Parser { } @Override - public FiltersAggregator.FiltersAggregatorBuilder getFactoryPrototypes() { - return FiltersAggregator.FiltersAggregatorBuilder.PROTOTYPE; + public FiltersAggregatorBuilder getFactoryPrototypes() { + return FiltersAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorBuilder.java new file mode 100644 index 00000000000..1931fd7ce96 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorBuilder.java @@ -0,0 +1,221 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.geogrid; + +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.spatial.util.GeoHashUtils; +import org.elasticsearch.common.geo.GeoPoint; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.fielddata.MultiGeoPointValues; +import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortingNumericDocValues; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.bucket.BucketUtils; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; + +import java.io.IOException; +import java.util.Objects; + +public class GeoGridAggregatorBuilder extends ValuesSourceAggregatorBuilder { + + static final GeoGridAggregatorBuilder PROTOTYPE = new GeoGridAggregatorBuilder(""); + + private int precision = GeoHashGridParser.DEFAULT_PRECISION; + private int requiredSize = GeoHashGridParser.DEFAULT_MAX_NUM_CELLS; + private int shardSize = -1; + + public GeoGridAggregatorBuilder(String name) { + super(name, InternalGeoHashGrid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); + } + + public GeoGridAggregatorBuilder precision(int precision) { + this.precision = GeoHashGridParams.checkPrecision(precision); + return this; + } + + public int precision() { + return precision; + } + + public GeoGridAggregatorBuilder size(int size) { + if (size < -1) { + throw new IllegalArgumentException( + "[size] must be greater than or equal to 0. Found [" + shardSize + "] in [" + name + "]"); + } + this.requiredSize = size; + return this; + } + + public int size() { + return requiredSize; + } + + public GeoGridAggregatorBuilder shardSize(int shardSize) { + if (shardSize < -1) { + throw new IllegalArgumentException( + "[shardSize] must be greater than or equal to 0. Found [" + shardSize + "] in [" + name + "]"); + } + this.shardSize = shardSize; + return this; + } + + public int shardSize() { + return shardSize; + } + + @Override + protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, + ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) + throws IOException { + int shardSize = this.shardSize; + if (shardSize == 0) { + shardSize = Integer.MAX_VALUE; + } + + int requiredSize = this.requiredSize; + if (requiredSize == 0) { + requiredSize = Integer.MAX_VALUE; + } + + if (shardSize < 0) { + // Use default heuristic to avoid any wrong-ranking caused by distributed counting + shardSize = BucketUtils.suggestShardSideQueueSize(requiredSize, context.searchContext().numberOfShards()); + } + + if (shardSize < requiredSize) { + shardSize = requiredSize; + } + return new GeoHashGridAggregatorFactory(name, type, config, precision, requiredSize, shardSize, context, parent, + subFactoriesBuilder, metaData); + } + + @Override + protected GeoGridAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType, + StreamInput in) throws IOException { + GeoGridAggregatorBuilder factory = new GeoGridAggregatorBuilder(name); + factory.precision = in.readVInt(); + factory.requiredSize = in.readVInt(); + factory.shardSize = in.readVInt(); + return factory; + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeVInt(precision); + out.writeVInt(requiredSize); + out.writeVInt(shardSize); + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + builder.field(GeoHashGridParams.FIELD_PRECISION.getPreferredName(), precision); + builder.field(GeoHashGridParams.FIELD_SIZE.getPreferredName(), requiredSize); + builder.field(GeoHashGridParams.FIELD_SHARD_SIZE.getPreferredName(), shardSize); + return builder; + } + + @Override + protected boolean innerEquals(Object obj) { + GeoGridAggregatorBuilder other = (GeoGridAggregatorBuilder) obj; + if (precision != other.precision) { + return false; + } + if (requiredSize != other.requiredSize) { + return false; + } + if (shardSize != other.shardSize) { + return false; + } + return true; + } + + @Override + protected int innerHashCode() { + return Objects.hash(precision, requiredSize, shardSize); + } + + private static class CellValues extends SortingNumericDocValues { + private MultiGeoPointValues geoValues; + private int precision; + + protected CellValues(MultiGeoPointValues geoValues, int precision) { + this.geoValues = geoValues; + this.precision = precision; + } + + @Override + public void setDocument(int docId) { + geoValues.setDocument(docId); + resize(geoValues.count()); + for (int i = 0; i < count(); ++i) { + GeoPoint target = geoValues.valueAt(i); + values[i] = GeoHashUtils.longEncode(target.getLon(), target.getLat(), precision); + } + sort(); + } + } + + static class CellIdSource extends ValuesSource.Numeric { + private final ValuesSource.GeoPoint valuesSource; + private final int precision; + + public CellIdSource(ValuesSource.GeoPoint valuesSource, int precision) { + this.valuesSource = valuesSource; + //different GeoPoints could map to the same or different geohash cells. + this.precision = precision; + } + + public int precision() { + return precision; + } + + @Override + public boolean isFloatingPoint() { + return false; + } + + @Override + public SortedNumericDocValues longValues(LeafReaderContext ctx) { + return new CellValues(valuesSource.geoPointValues(ctx), precision); + } + + @Override + public SortedNumericDoubleValues doubleValues(LeafReaderContext ctx) { + throw new UnsupportedOperationException(); + } + + @Override + public SortedBinaryDocValues bytesValues(LeafReaderContext ctx) { + throw new UnsupportedOperationException(); + } + + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregator.java index c00f90c9ef1..d63c30272bc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregator.java @@ -46,10 +46,10 @@ public class GeoHashGridAggregator extends BucketsAggregator { private final int requiredSize; private final int shardSize; - private final GeoHashGridParser.GeoGridAggregatorBuilder.CellIdSource valuesSource; + private final GeoGridAggregatorBuilder.CellIdSource valuesSource; private final LongHash bucketOrds; - public GeoHashGridAggregator(String name, AggregatorFactories factories, GeoHashGridParser.GeoGridAggregatorBuilder.CellIdSource valuesSource, + public GeoHashGridAggregator(String name, AggregatorFactories factories, GeoGridAggregatorBuilder.CellIdSource valuesSource, int requiredSize, int shardSize, AggregationContext aggregationContext, Aggregator parent, List pipelineAggregators, Map metaData) throws IOException { super(name, factories, aggregationContext, parent, pipelineAggregators, metaData); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregatorFactory.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregatorFactory.java index 4659060c1ae..ba4f84017c1 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregatorFactory.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregatorFactory.java @@ -23,22 +23,21 @@ import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; -import org.elasticsearch.search.aggregations.NonCollectingAggregator; import org.elasticsearch.search.aggregations.InternalAggregation.Type; -import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridParser.GeoGridAggregatorBuilder.CellIdSource; +import org.elasticsearch.search.aggregations.NonCollectingAggregator; +import org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregatorBuilder.CellIdSource; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSource.GeoPoint; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Map; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; - public class GeoHashGridAggregatorFactory extends ValuesSourceAggregatorFactory { private final int precision; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridParser.java index a4eada5454c..d387771465a 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridParser.java @@ -18,37 +18,17 @@ */ package org.elasticsearch.search.aggregations.bucket.geogrid; -import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; -import org.apache.lucene.spatial.util.GeoHashUtils; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.geo.GeoPoint; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser.Token; -import org.elasticsearch.index.fielddata.MultiGeoPointValues; -import org.elasticsearch.index.fielddata.SortedBinaryDocValues; -import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; -import org.elasticsearch.index.fielddata.SortingNumericDocValues; import org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; -import org.elasticsearch.search.aggregations.bucket.BucketUtils; import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.GeoPointValuesSourceParser; -import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; -import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; import java.util.Map; -import java.util.Objects; /** * Aggregates Geo information into cells determined by geohashes of a given precision. @@ -110,180 +90,4 @@ public class GeoHashGridParser extends GeoPointValuesSourceParser { } return false; } - - public static class GeoGridAggregatorBuilder extends ValuesSourceAggregatorBuilder { - - static final GeoGridAggregatorBuilder PROTOTYPE = new GeoGridAggregatorBuilder(""); - - private int precision = DEFAULT_PRECISION; - private int requiredSize = DEFAULT_MAX_NUM_CELLS; - private int shardSize = -1; - - public GeoGridAggregatorBuilder(String name) { - super(name, InternalGeoHashGrid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); - } - - public GeoGridAggregatorBuilder precision(int precision) { - this.precision = GeoHashGridParams.checkPrecision(precision); - return this; - } - - public int precision() { - return precision; - } - - public GeoGridAggregatorBuilder size(int size) { - if (size < -1) { - throw new IllegalArgumentException( - "[size] must be greater than or equal to 0. Found [" + shardSize + "] in [" + name + "]"); - } - this.requiredSize = size; - return this; - } - - public int size() { - return requiredSize; - } - - public GeoGridAggregatorBuilder shardSize(int shardSize) { - if (shardSize < -1) { - throw new IllegalArgumentException( - "[shardSize] must be greater than or equal to 0. Found [" + shardSize + "] in [" + name + "]"); - } - this.shardSize = shardSize; - return this; - } - - public int shardSize() { - return shardSize; - } - - @Override - protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, - ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) - throws IOException { - int shardSize = this.shardSize; - if (shardSize == 0) { - shardSize = Integer.MAX_VALUE; - } - - int requiredSize = this.requiredSize; - if (requiredSize == 0) { - requiredSize = Integer.MAX_VALUE; - } - - if (shardSize < 0) { - // Use default heuristic to avoid any wrong-ranking caused by distributed counting - shardSize = BucketUtils.suggestShardSideQueueSize(requiredSize, context.searchContext().numberOfShards()); - } - - if (shardSize < requiredSize) { - shardSize = requiredSize; - } - return new GeoHashGridAggregatorFactory(name, type, config, precision, requiredSize, shardSize, context, parent, - subFactoriesBuilder, metaData); - } - - @Override - protected GeoGridAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType, - StreamInput in) throws IOException { - GeoGridAggregatorBuilder factory = new GeoGridAggregatorBuilder(name); - factory.precision = in.readVInt(); - factory.requiredSize = in.readVInt(); - factory.shardSize = in.readVInt(); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeVInt(precision); - out.writeVInt(requiredSize); - out.writeVInt(shardSize); - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.field(GeoHashGridParams.FIELD_PRECISION.getPreferredName(), precision); - builder.field(GeoHashGridParams.FIELD_SIZE.getPreferredName(), requiredSize); - builder.field(GeoHashGridParams.FIELD_SHARD_SIZE.getPreferredName(), shardSize); - return builder; - } - - @Override - protected boolean innerEquals(Object obj) { - GeoGridAggregatorBuilder other = (GeoGridAggregatorBuilder) obj; - if (precision != other.precision) { - return false; - } - if (requiredSize != other.requiredSize) { - return false; - } - if (shardSize != other.shardSize) { - return false; - } - return true; - } - - @Override - protected int innerHashCode() { - return Objects.hash(precision, requiredSize, shardSize); - } - - private static class CellValues extends SortingNumericDocValues { - private MultiGeoPointValues geoValues; - private int precision; - - protected CellValues(MultiGeoPointValues geoValues, int precision) { - this.geoValues = geoValues; - this.precision = precision; - } - - @Override - public void setDocument(int docId) { - geoValues.setDocument(docId); - resize(geoValues.count()); - for (int i = 0; i < count(); ++i) { - GeoPoint target = geoValues.valueAt(i); - values[i] = GeoHashUtils.longEncode(target.getLon(), target.getLat(), precision); - } - sort(); - } - } - - static class CellIdSource extends ValuesSource.Numeric { - private final ValuesSource.GeoPoint valuesSource; - private final int precision; - - public CellIdSource(ValuesSource.GeoPoint valuesSource, int precision) { - this.valuesSource = valuesSource; - //different GeoPoints could map to the same or different geohash cells. - this.precision = precision; - } - - public int precision() { - return precision; - } - - @Override - public boolean isFloatingPoint() { - return false; - } - - @Override - public SortedNumericDocValues longValues(LeafReaderContext ctx) { - return new CellValues(valuesSource.geoPointValues(ctx), precision); - } - - @Override - public SortedNumericDoubleValues doubleValues(LeafReaderContext ctx) { - throw new UnsupportedOperationException(); - } - - @Override - public SortedBinaryDocValues bytesValues(LeafReaderContext ctx) { - throw new UnsupportedOperationException(); - } - - } - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java index caa4d2bb35b..6e4980ede27 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java @@ -19,16 +19,10 @@ package org.elasticsearch.search.aggregations.bucket.global; import org.apache.lucene.index.LeafReaderContext; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; @@ -70,47 +64,4 @@ public class GlobalAggregator extends SingleBucketAggregator { public InternalAggregation buildEmptyAggregation() { throw new UnsupportedOperationException("global aggregations cannot serve as sub-aggregations, hence should never be called on #buildEmptyAggregations"); } - - public static class GlobalAggregatorBuilder extends AggregatorBuilder { - - static final GlobalAggregatorBuilder PROTOTYPE = new GlobalAggregatorBuilder(""); - - public GlobalAggregatorBuilder(String name) { - super(name, InternalGlobal.TYPE); - } - - @Override - protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) - throws IOException { - return new GlobalAggregatorFactory(name, type, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected GlobalAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { - return new GlobalAggregatorBuilder(name); - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - // Nothing to write - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.endObject(); - return builder; - } - - @Override - protected boolean doEquals(Object obj) { - return true; - } - - @Override - protected int doHashCode() { - return 0; - } - - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregatorBuilder.java new file mode 100644 index 00000000000..14921b358cd --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregatorBuilder.java @@ -0,0 +1,73 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.global; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; + +import java.io.IOException; + +public class GlobalAggregatorBuilder extends AggregatorBuilder { + + static final GlobalAggregatorBuilder PROTOTYPE = new GlobalAggregatorBuilder(""); + + public GlobalAggregatorBuilder(String name) { + super(name, InternalGlobal.TYPE); + } + + @Override + protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) + throws IOException { + return new GlobalAggregatorFactory(name, type, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected GlobalAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { + return new GlobalAggregatorBuilder(name); + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + // Nothing to write + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.endObject(); + return builder; + } + + @Override + protected boolean doEquals(Object obj) { + return true; + } + + @Override + protected int doHashCode() { + return 0; + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java index 8366a072de7..2a0ff5fb025 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java @@ -34,15 +34,15 @@ public class GlobalParser implements Aggregator.Parser { } @Override - public GlobalAggregator.GlobalAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) + public GlobalAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException { parser.nextToken(); - return new GlobalAggregator.GlobalAggregatorBuilder(aggregationName); + return new GlobalAggregatorBuilder(aggregationName); } @Override - public GlobalAggregator.GlobalAggregatorBuilder getFactoryPrototypes() { - return GlobalAggregator.GlobalAggregatorBuilder.PROTOTYPE; + public GlobalAggregatorBuilder getFactoryPrototypes() { + return GlobalAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AbstractHistogramBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AbstractHistogramBuilder.java new file mode 100644 index 00000000000..501a0082d56 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AbstractHistogramBuilder.java @@ -0,0 +1,211 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.histogram; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.rounding.Rounding; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import java.io.IOException; +import java.util.Objects; + +public abstract class AbstractHistogramBuilder> + extends ValuesSourceAggregatorBuilder { + + protected long interval; + protected long offset = 0; + protected InternalOrder order = (InternalOrder) Histogram.Order.KEY_ASC; + protected boolean keyed = false; + protected long minDocCount = 0; + protected ExtendedBounds extendedBounds; + + AbstractHistogramBuilder(String name, InternalHistogram.Factory histogramFactory) { + super(name, histogramFactory.type(), ValuesSourceType.NUMERIC, histogramFactory.valueType()); + } + + public long interval() { + return interval; + } + + @SuppressWarnings("unchecked") + public AB interval(long interval) { + if (interval < 1) { + throw new IllegalArgumentException("[interval] must be 1 or greater for histogram aggregation [" + name + "]"); + } + this.interval = interval; + return (AB) this; + } + + public long offset() { + return offset; + } + + @SuppressWarnings("unchecked") + public AB offset(long offset) { + this.offset = offset; + return (AB) this; + } + + public Histogram.Order order() { + return order; + } + + @SuppressWarnings("unchecked") + public AB order(Histogram.Order order) { + if (order == null) { + throw new IllegalArgumentException("[order] must not be null: [" + name + "]"); + } + this.order = (InternalOrder) order; + return (AB) this; + } + + public boolean keyed() { + return keyed; + } + + @SuppressWarnings("unchecked") + public AB keyed(boolean keyed) { + this.keyed = keyed; + return (AB) this; + } + + public long minDocCount() { + return minDocCount; + } + + @SuppressWarnings("unchecked") + public AB minDocCount(long minDocCount) { + if (minDocCount < 0) { + throw new IllegalArgumentException( + "[minDocCount] must be greater than or equal to 0. Found [" + minDocCount + "] in [" + name + "]"); + } + this.minDocCount = minDocCount; + return (AB) this; + } + + public ExtendedBounds extendedBounds() { + return extendedBounds; + } + + @SuppressWarnings("unchecked") + public AB extendedBounds(ExtendedBounds extendedBounds) { + if (extendedBounds == null) { + throw new IllegalArgumentException("[extendedBounds] must not be null: [" + name + "]"); + } + this.extendedBounds = extendedBounds; + return (AB) this; + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + + builder.field(Rounding.Interval.INTERVAL_FIELD.getPreferredName()); + doXContentInterval(builder, params); + builder.field(Rounding.OffsetRounding.OFFSET_FIELD.getPreferredName(), offset); + + if (order != null) { + builder.field(HistogramAggregator.ORDER_FIELD.getPreferredName()); + order.toXContent(builder, params); + } + + builder.field(HistogramAggregator.KEYED_FIELD.getPreferredName(), keyed); + + builder.field(HistogramAggregator.MIN_DOC_COUNT_FIELD.getPreferredName(), minDocCount); + + if (extendedBounds != null) { + extendedBounds.toXContent(builder, params); + } + + return builder; + } + + protected XContentBuilder doXContentInterval(XContentBuilder builder, Params params) throws IOException { + builder.value(interval); + return builder; + } + + @Override + public String getWriteableName() { + return InternalHistogram.TYPE.name(); + } + + @SuppressWarnings("unchecked") + @Override + protected AB innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in) + throws IOException { + AbstractHistogramBuilder factory = createFactoryFromStream(name, in); + factory.interval = in.readVLong(); + factory.offset = in.readLong(); + if (in.readBoolean()) { + factory.order = InternalOrder.Streams.readOrder(in); + } + factory.keyed = in.readBoolean(); + factory.minDocCount = in.readVLong(); + if (in.readBoolean()) { + factory.extendedBounds = ExtendedBounds.readFrom(in); + } + return (AB) factory; + } + + protected abstract AB createFactoryFromStream(String name, StreamInput in) throws IOException; + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + writeFactoryToStream(out); + out.writeVLong(interval); + out.writeLong(offset); + boolean hasOrder = order != null; + out.writeBoolean(hasOrder); + if (hasOrder) { + InternalOrder.Streams.writeOrder(order, out); + } + out.writeBoolean(keyed); + out.writeVLong(minDocCount); + boolean hasExtendedBounds = extendedBounds != null; + out.writeBoolean(hasExtendedBounds); + if (hasExtendedBounds) { + extendedBounds.writeTo(out); + } + } + + protected void writeFactoryToStream(StreamOutput out) throws IOException { + // Default impl does nothing +} + + @Override + protected int innerHashCode() { + return Objects.hash(interval, offset, order, keyed, minDocCount, extendedBounds); +} + + @Override + protected boolean innerEquals(Object obj) { + AbstractHistogramBuilder other = (AbstractHistogramBuilder) obj; + return Objects.equals(interval, other.interval) + && Objects.equals(offset, other.offset) + && Objects.equals(order, other.order) + && Objects.equals(keyed, other.keyed) + && Objects.equals(minDocCount, other.minDocCount) + && Objects.equals(extendedBounds, other.extendedBounds); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorBuilder.java new file mode 100644 index 00000000000..7f08f7ba01c --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorBuilder.java @@ -0,0 +1,129 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.histogram; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; + +import java.io.IOException; +import java.util.Objects; + +public class DateHistogramAggregatorBuilder extends AbstractHistogramBuilder { + + public static final DateHistogramAggregatorBuilder PROTOTYPE = new DateHistogramAggregatorBuilder(""); + + private DateHistogramInterval dateHistogramInterval; + + public DateHistogramAggregatorBuilder(String name) { + super(name, InternalDateHistogram.HISTOGRAM_FACTORY); + } + + /** + * Set the interval. + */ + public DateHistogramAggregatorBuilder dateHistogramInterval(DateHistogramInterval dateHistogramInterval) { + if (dateHistogramInterval == null) { + throw new IllegalArgumentException("[dateHistogramInterval] must not be null: [" + name + "]"); + } + this.dateHistogramInterval = dateHistogramInterval; + return this; + } + + public DateHistogramAggregatorBuilder offset(String offset) { + if (offset == null) { + throw new IllegalArgumentException("[offset] must not be null: [" + name + "]"); + } + return offset(parseStringOffset(offset)); + } + + protected static long parseStringOffset(String offset) { + if (offset.charAt(0) == '-') { + return -TimeValue + .parseTimeValue(offset.substring(1), null, DateHistogramAggregatorBuilder.class.getSimpleName() + ".parseOffset") + .millis(); + } + int beginIndex = offset.charAt(0) == '+' ? 1 : 0; + return TimeValue + .parseTimeValue(offset.substring(beginIndex), null, DateHistogramAggregatorBuilder.class.getSimpleName() + ".parseOffset") + .millis(); + } + + public DateHistogramInterval dateHistogramInterval() { + return dateHistogramInterval; + } + + @Override + protected DateHistogramAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new DateHistogramAggregatorFactory(name, type, config, interval, dateHistogramInterval, offset, order, keyed, minDocCount, + extendedBounds, context, parent, subFactoriesBuilder, metaData); + } + + @Override + public String getWriteableName() { + return InternalDateHistogram.TYPE.name(); + } + + @Override + protected XContentBuilder doXContentInterval(XContentBuilder builder, Params params) throws IOException { + if (dateHistogramInterval == null) { + super.doXContentInterval(builder, params); + } else { + builder.value(dateHistogramInterval.toString()); + } + return builder; + } + + @Override + protected DateHistogramAggregatorBuilder createFactoryFromStream(String name, StreamInput in) throws IOException { + DateHistogramAggregatorBuilder factory = new DateHistogramAggregatorBuilder(name); + if (in.readBoolean()) { + factory.dateHistogramInterval = DateHistogramInterval.readFromStream(in); + } + return factory; + } + + @Override + protected void writeFactoryToStream(StreamOutput out) throws IOException { + boolean hasDateInterval = dateHistogramInterval != null; + out.writeBoolean(hasDateInterval); + if (hasDateInterval) { + dateHistogramInterval.writeTo(out); + } + } + + @Override + protected int innerHashCode() { + return Objects.hash(super.innerHashCode(), dateHistogramInterval); + } + + @Override + protected boolean innerEquals(Object obj) { + DateHistogramAggregatorBuilder other = (DateHistogramAggregatorBuilder) obj; + return super.innerEquals(obj) && Objects.equals(dateHistogramInterval, other.dateHistogramInterval); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramParser.java index 2ed44e72866..1c03f9fb28b 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramParser.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.bucket.histogram; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.rounding.Rounding; -import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator.DateHistogramAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; @@ -50,7 +49,7 @@ public class DateHistogramParser extends HistogramParser { @Override protected DateHistogramAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - HistogramAggregator.DateHistogramAggregatorBuilder factory = new HistogramAggregator.DateHistogramAggregatorBuilder(aggregationName); + DateHistogramAggregatorBuilder factory = new DateHistogramAggregatorBuilder(aggregationName); Object interval = otherOptions.get(Rounding.Interval.INTERVAL_FIELD); if (interval == null) { throw new ParsingException(null, "Missing required field [interval] for histogram aggregation [" + aggregationName + "]"); @@ -100,6 +99,6 @@ public class DateHistogramParser extends HistogramParser { @Override public DateHistogramAggregatorBuilder getFactoryPrototypes() { - return HistogramAggregator.DateHistogramAggregatorBuilder.PROTOTYPE; + return DateHistogramAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregator.java index d3bc9b93975..b471e11d25c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregator.java @@ -23,29 +23,18 @@ import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.inject.internal.Nullable; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.rounding.Rounding; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.LongHash; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.bucket.BucketsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; @@ -53,7 +42,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; public class HistogramAggregator extends BucketsAggregator { @@ -158,301 +146,4 @@ public class HistogramAggregator extends BucketsAggregator { public void doClose() { Releasables.close(bucketOrds); } - - public static class HistogramAggregatorBuilder extends AbstractBuilder { - public static final HistogramAggregatorBuilder PROTOTYPE = new HistogramAggregatorBuilder(""); - - public HistogramAggregatorBuilder(String name) { - super(name, InternalHistogram.HISTOGRAM_FACTORY); - } - - @Override - protected HistogramAggregatorBuilder createFactoryFromStream(String name, StreamInput in) throws IOException { - return new HistogramAggregatorBuilder(name); - } - - @Override - protected HistogramAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new HistogramAggregatorFactory(name, type, config, interval, offset, order, keyed, minDocCount, extendedBounds, context, - parent, subFactoriesBuilder, metaData); - } - - } - - public static abstract class AbstractBuilder> - extends ValuesSourceAggregatorBuilder { - - protected long interval; - protected long offset = 0; - protected InternalOrder order = (InternalOrder) Histogram.Order.KEY_ASC; - protected boolean keyed = false; - protected long minDocCount = 0; - protected ExtendedBounds extendedBounds; - - private AbstractBuilder(String name, InternalHistogram.Factory histogramFactory) { - super(name, histogramFactory.type(), ValuesSourceType.NUMERIC, histogramFactory.valueType()); - } - - public long interval() { - return interval; - } - - @SuppressWarnings("unchecked") - public AB interval(long interval) { - if (interval < 1) { - throw new IllegalArgumentException("[interval] must be 1 or greater for histogram aggregation [" + name + "]"); - } - this.interval = interval; - return (AB) this; - } - - public long offset() { - return offset; - } - - @SuppressWarnings("unchecked") - public AB offset(long offset) { - this.offset = offset; - return (AB) this; - } - - public Histogram.Order order() { - return order; - } - - @SuppressWarnings("unchecked") - public AB order(Histogram.Order order) { - if (order == null) { - throw new IllegalArgumentException("[order] must not be null: [" + name + "]"); - } - this.order = (InternalOrder) order; - return (AB) this; - } - - public boolean keyed() { - return keyed; - } - - @SuppressWarnings("unchecked") - public AB keyed(boolean keyed) { - this.keyed = keyed; - return (AB) this; - } - - public long minDocCount() { - return minDocCount; - } - - @SuppressWarnings("unchecked") - public AB minDocCount(long minDocCount) { - if (minDocCount < 0) { - throw new IllegalArgumentException( - "[minDocCount] must be greater than or equal to 0. Found [" + minDocCount + "] in [" + name + "]"); - } - this.minDocCount = minDocCount; - return (AB) this; - } - - public ExtendedBounds extendedBounds() { - return extendedBounds; - } - - @SuppressWarnings("unchecked") - public AB extendedBounds(ExtendedBounds extendedBounds) { - if (extendedBounds == null) { - throw new IllegalArgumentException("[extendedBounds] must not be null: [" + name + "]"); - } - this.extendedBounds = extendedBounds; - return (AB) this; - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - - builder.field(Rounding.Interval.INTERVAL_FIELD.getPreferredName()); - doXContentInterval(builder, params); - builder.field(Rounding.OffsetRounding.OFFSET_FIELD.getPreferredName(), offset); - - if (order != null) { - builder.field(ORDER_FIELD.getPreferredName()); - order.toXContent(builder, params); - } - - builder.field(KEYED_FIELD.getPreferredName(), keyed); - - builder.field(MIN_DOC_COUNT_FIELD.getPreferredName(), minDocCount); - - if (extendedBounds != null) { - extendedBounds.toXContent(builder, params); - } - - return builder; - } - - protected XContentBuilder doXContentInterval(XContentBuilder builder, Params params) throws IOException { - builder.value(interval); - return builder; - } - - @Override - public String getWriteableName() { - return InternalHistogram.TYPE.name(); - } - - @SuppressWarnings("unchecked") - @Override - protected AB innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in) - throws IOException { - AbstractBuilder factory = createFactoryFromStream(name, in); - factory.interval = in.readVLong(); - factory.offset = in.readLong(); - if (in.readBoolean()) { - factory.order = InternalOrder.Streams.readOrder(in); - } - factory.keyed = in.readBoolean(); - factory.minDocCount = in.readVLong(); - if (in.readBoolean()) { - factory.extendedBounds = ExtendedBounds.readFrom(in); - } - return (AB) factory; - } - - protected abstract AB createFactoryFromStream(String name, StreamInput in) throws IOException; - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - writeFactoryToStream(out); - out.writeVLong(interval); - out.writeLong(offset); - boolean hasOrder = order != null; - out.writeBoolean(hasOrder); - if (hasOrder) { - InternalOrder.Streams.writeOrder(order, out); - } - out.writeBoolean(keyed); - out.writeVLong(minDocCount); - boolean hasExtendedBounds = extendedBounds != null; - out.writeBoolean(hasExtendedBounds); - if (hasExtendedBounds) { - extendedBounds.writeTo(out); - } - } - - protected void writeFactoryToStream(StreamOutput out) throws IOException { - // Default impl does nothing - } - - @Override - protected int innerHashCode() { - return Objects.hash(interval, offset, order, keyed, minDocCount, extendedBounds); - } - - @Override - protected boolean innerEquals(Object obj) { - AbstractBuilder other = (AbstractBuilder) obj; - return Objects.equals(interval, other.interval) - && Objects.equals(offset, other.offset) - && Objects.equals(order, other.order) - && Objects.equals(keyed, other.keyed) - && Objects.equals(minDocCount, other.minDocCount) - && Objects.equals(extendedBounds, other.extendedBounds); - } - } - - public static class DateHistogramAggregatorBuilder extends AbstractBuilder { - - public static final DateHistogramAggregatorBuilder PROTOTYPE = new DateHistogramAggregatorBuilder(""); - - private DateHistogramInterval dateHistogramInterval; - - public DateHistogramAggregatorBuilder(String name) { - super(name, InternalDateHistogram.HISTOGRAM_FACTORY); - } - - /** - * Set the interval. - */ - public DateHistogramAggregatorBuilder dateHistogramInterval(DateHistogramInterval dateHistogramInterval) { - if (dateHistogramInterval == null) { - throw new IllegalArgumentException("[dateHistogramInterval] must not be null: [" + name + "]"); - } - this.dateHistogramInterval = dateHistogramInterval; - return this; - } - - public DateHistogramAggregatorBuilder offset(String offset) { - if (offset == null) { - throw new IllegalArgumentException("[offset] must not be null: [" + name + "]"); - } - return offset(parseStringOffset(offset)); - } - - protected static long parseStringOffset(String offset) { - if (offset.charAt(0) == '-') { - return -TimeValue.parseTimeValue(offset.substring(1), null, DateHistogramAggregatorBuilder.class.getSimpleName() + ".parseOffset") - .millis(); - } - int beginIndex = offset.charAt(0) == '+' ? 1 : 0; - return TimeValue.parseTimeValue(offset.substring(beginIndex), null, DateHistogramAggregatorBuilder.class.getSimpleName() + ".parseOffset") - .millis(); - } - - public DateHistogramInterval dateHistogramInterval() { - return dateHistogramInterval; - } - - @Override - protected DateHistogramAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new DateHistogramAggregatorFactory(name, type, config, interval, dateHistogramInterval, offset, order, keyed, - minDocCount, extendedBounds, context, parent, subFactoriesBuilder, metaData); - } - - @Override - public String getWriteableName() { - return InternalDateHistogram.TYPE.name(); - } - - @Override - protected XContentBuilder doXContentInterval(XContentBuilder builder, Params params) throws IOException { - if (dateHistogramInterval == null) { - super.doXContentInterval(builder, params); - } else { - builder.value(dateHistogramInterval.toString()); - } - return builder; - } - - @Override - protected DateHistogramAggregatorBuilder createFactoryFromStream(String name, StreamInput in) - throws IOException { - DateHistogramAggregatorBuilder factory = new DateHistogramAggregatorBuilder(name); - if (in.readBoolean()) { - factory.dateHistogramInterval = DateHistogramInterval.readFromStream(in); - } - return factory; - } - - @Override - protected void writeFactoryToStream(StreamOutput out) throws IOException { - boolean hasDateInterval = dateHistogramInterval != null; - out.writeBoolean(hasDateInterval); - if (hasDateInterval) { - dateHistogramInterval.writeTo(out); - } - } - - @Override - protected int innerHashCode() { - return Objects.hash(super.innerHashCode(), dateHistogramInterval); - } - - @Override - protected boolean innerEquals(Object obj) { - DateHistogramAggregatorBuilder other = (DateHistogramAggregatorBuilder) obj; - return super.innerEquals(obj) - && Objects.equals(dateHistogramInterval, other.dateHistogramInterval); - } - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorBuilder.java new file mode 100644 index 00000000000..cfd63cea5be --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorBuilder.java @@ -0,0 +1,50 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.histogram; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; + +import java.io.IOException; + +public class HistogramAggregatorBuilder extends AbstractHistogramBuilder { + public static final HistogramAggregatorBuilder PROTOTYPE = new HistogramAggregatorBuilder(""); + + public HistogramAggregatorBuilder(String name) { + super(name, InternalHistogram.HISTOGRAM_FACTORY); + } + + @Override + protected HistogramAggregatorBuilder createFactoryFromStream(String name, StreamInput in) throws IOException { + return new HistogramAggregatorBuilder(name); + } + + @Override + protected HistogramAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new HistogramAggregatorFactory(name, type, config, interval, offset, order, keyed, minDocCount, extendedBounds, context, + parent, subFactoriesBuilder, metaData); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramParser.java index 521fe0e5efd..c30cc5919e1 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramParser.java @@ -50,9 +50,9 @@ public class HistogramParser extends NumericValuesSourceParser { } @Override - protected HistogramAggregator.AbstractBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected AbstractHistogramBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - HistogramAggregator.HistogramAggregatorBuilder factory = new HistogramAggregator.HistogramAggregatorBuilder(aggregationName); + HistogramAggregatorBuilder factory = new HistogramAggregatorBuilder(aggregationName); Long interval = (Long) otherOptions.get(Rounding.Interval.INTERVAL_FIELD); if (interval == null) { throw new ParsingException(null, "Missing required field [interval] for histogram aggregation [" + aggregationName + "]"); @@ -162,7 +162,7 @@ public class HistogramParser extends NumericValuesSourceParser { } @Override - public HistogramAggregator.AbstractBuilder getFactoryPrototypes() { - return HistogramAggregator.HistogramAggregatorBuilder.PROTOTYPE; + public AbstractHistogramBuilder getFactoryPrototypes() { + return HistogramAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregator.java index 8169270fede..e80be56f341 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregator.java @@ -20,25 +20,15 @@ package org.elasticsearch.search.aggregations.bucket.missing; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.util.Bits; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; import java.util.List; @@ -89,47 +79,6 @@ public class MissingAggregator extends SingleBucketAggregator { return new InternalMissing(name, 0, buildEmptySubAggregations(), pipelineAggregators(), metaData()); } - public static class MissingAggregatorBuilder extends ValuesSourceAggregatorBuilder { - - static final MissingAggregatorBuilder PROTOTYPE = new MissingAggregatorBuilder("", null); - - public MissingAggregatorBuilder(String name, ValueType targetValueType) { - super(name, InternalMissing.TYPE, ValuesSourceType.ANY, targetValueType); - } - - @Override - protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, - ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new MissingAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected MissingAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new MissingAggregatorBuilder(name, targetValueType); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(Object obj) { - return true; - } - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorBuilder.java new file mode 100644 index 00000000000..3bbd2db2e43 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorBuilder.java @@ -0,0 +1,76 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.missing; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; + +import java.io.IOException; + +public class MissingAggregatorBuilder extends ValuesSourceAggregatorBuilder { + + static final MissingAggregatorBuilder PROTOTYPE = new MissingAggregatorBuilder("", null); + + public MissingAggregatorBuilder(String name, ValueType targetValueType) { + super(name, InternalMissing.TYPE, ValuesSourceType.ANY, targetValueType); + } + + @Override + protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, + ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new MissingAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected MissingAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) { + return new MissingAggregatorBuilder(name, targetValueType); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(Object obj) { + return true; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingParser.java index 8abc4a2e951..5b34493111e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingParser.java @@ -46,13 +46,13 @@ public class MissingParser extends AnyValuesSourceParser { } @Override - protected MissingAggregator.MissingAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected MissingAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - return new MissingAggregator.MissingAggregatorBuilder(aggregationName, targetValueType); + return new MissingAggregatorBuilder(aggregationName, targetValueType); } @Override - public MissingAggregator.MissingAggregatorBuilder getFactoryPrototypes() { - return MissingAggregator.MissingAggregatorBuilder.PROTOTYPE; + public MissingAggregatorBuilder getFactoryPrototypes() { + return MissingAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregator.java index d9d56a9854f..677951c52c0 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregator.java @@ -29,19 +29,13 @@ import org.apache.lucene.search.Weight; import org.apache.lucene.search.join.BitSetProducer; import org.apache.lucene.util.BitSet; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.mapper.object.ObjectMapper; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; @@ -49,7 +43,6 @@ import org.elasticsearch.search.aggregations.support.AggregationContext; import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Objects; /** * @@ -150,70 +143,4 @@ public class NestedAggregator extends SingleBucketAggregator { return null; } - public static class NestedAggregatorBuilder extends AggregatorBuilder { - - static final NestedAggregatorBuilder PROTOTYPE = new NestedAggregatorBuilder("", ""); - - private final String path; - - /** - * @param name - * the name of this aggregation - * @param path - * the path to use for this nested aggregation. The path must - * match the path to a nested object in the mappings. - */ - public NestedAggregatorBuilder(String name, String path) { - super(name, InternalNested.TYPE); - if (path == null) { - throw new IllegalArgumentException("[path] must not be null: [" + name + "]"); - } - this.path = path; - } - - /** - * Get the path to use for this nested aggregation. - */ - public String path() { - return path; - } - - @Override - protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) - throws IOException { - return new NestedAggregatorFactory(name, type, path, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.field(PATH_FIELD.getPreferredName(), path); - builder.endObject(); - return builder; - } - - @Override - protected NestedAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { - String path = in.readString(); - NestedAggregatorBuilder factory = new NestedAggregatorBuilder(name, path); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeString(path); - } - - @Override - protected int doHashCode() { - return Objects.hash(path); - } - - @Override - protected boolean doEquals(Object obj) { - NestedAggregatorBuilder other = (NestedAggregatorBuilder) obj; - return Objects.equals(path, other.path); - } - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorBuilder.java new file mode 100644 index 00000000000..724eaec09ab --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorBuilder.java @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.nested; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; + +import java.io.IOException; +import java.util.Objects; + +public class NestedAggregatorBuilder extends AggregatorBuilder { + + static final NestedAggregatorBuilder PROTOTYPE = new NestedAggregatorBuilder("", ""); + + private final String path; + + /** + * @param name + * the name of this aggregation + * @param path + * the path to use for this nested aggregation. The path must + * match the path to a nested object in the mappings. + */ + public NestedAggregatorBuilder(String name, String path) { + super(name, InternalNested.TYPE); + if (path == null) { + throw new IllegalArgumentException("[path] must not be null: [" + name + "]"); + } + this.path = path; + } + + /** + * Get the path to use for this nested aggregation. + */ + public String path() { + return path; + } + + @Override + protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) + throws IOException { + return new NestedAggregatorFactory(name, type, path, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.field(NestedAggregator.PATH_FIELD.getPreferredName(), path); + builder.endObject(); + return builder; + } + + @Override + protected NestedAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { + String path = in.readString(); + NestedAggregatorBuilder factory = new NestedAggregatorBuilder(name, path); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeString(path); + } + + @Override + protected int doHashCode() { + return Objects.hash(path); + } + + @Override + protected boolean doEquals(Object obj) { + NestedAggregatorBuilder other = (NestedAggregatorBuilder) obj; + return Objects.equals(path, other.path); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java index dabd7adab44..a4beae49f0e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java @@ -35,7 +35,7 @@ public class NestedParser implements Aggregator.Parser { } @Override - public NestedAggregator.NestedAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) + public NestedAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException { String path = null; @@ -61,11 +61,11 @@ public class NestedParser implements Aggregator.Parser { throw new ParsingException(parser.getTokenLocation(), "Missing [path] field for nested aggregation [" + aggregationName + "]"); } - return new NestedAggregator.NestedAggregatorBuilder(aggregationName, path); + return new NestedAggregatorBuilder(aggregationName, path); } @Override - public NestedAggregator.NestedAggregatorBuilder getFactoryPrototypes() { - return NestedAggregator.NestedAggregatorBuilder.PROTOTYPE; + public NestedAggregatorBuilder getFactoryPrototypes() { + return NestedAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregator.java index c65d551b7c6..a60d939b102 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregator.java @@ -25,19 +25,13 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.join.BitSetProducer; import org.apache.lucene.util.BitSet; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.mapper.object.ObjectMapper; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; @@ -45,7 +39,6 @@ import org.elasticsearch.search.aggregations.support.AggregationContext; import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Objects; /** * @@ -114,74 +107,4 @@ public class ReverseNestedAggregator extends SingleBucketAggregator { Query getParentFilter() { return parentFilter; } - - public static class ReverseNestedAggregatorBuilder extends AggregatorBuilder { - - static final ReverseNestedAggregatorBuilder PROTOTYPE = new ReverseNestedAggregatorBuilder(""); - - private String path; - - public ReverseNestedAggregatorBuilder(String name) { - super(name, InternalReverseNested.TYPE); - } - - /** - * Set the path to use for this nested aggregation. The path must match - * the path to a nested object in the mappings. If it is not specified - * then this aggregation will go back to the root document. - */ - public ReverseNestedAggregatorBuilder path(String path) { - if (path == null) { - throw new IllegalArgumentException("[path] must not be null: [" + name + "]"); - } - this.path = path; - return this; - } - - /** - * Get the path to use for this nested aggregation. - */ - public String path() { - return path; - } - - @Override - protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) - throws IOException { - return new ReverseNestedAggregatorFactory(name, type, path, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - if (path != null) { - builder.field(PATH_FIELD.getPreferredName(), path); - } - builder.endObject(); - return builder; - } - - @Override - protected ReverseNestedAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { - ReverseNestedAggregatorBuilder factory = new ReverseNestedAggregatorBuilder(name); - factory.path = in.readOptionalString(); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeOptionalString(path); - } - - @Override - protected int doHashCode() { - return Objects.hash(path); - } - - @Override - protected boolean doEquals(Object obj) { - ReverseNestedAggregatorBuilder other = (ReverseNestedAggregatorBuilder) obj; - return Objects.equals(path, other.path); - } - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregatorBuilder.java new file mode 100644 index 00000000000..ccb8fa294ed --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregatorBuilder.java @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.nested; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; + +import java.io.IOException; +import java.util.Objects; + +public class ReverseNestedAggregatorBuilder extends AggregatorBuilder { + + static final ReverseNestedAggregatorBuilder PROTOTYPE = new ReverseNestedAggregatorBuilder(""); + + private String path; + + public ReverseNestedAggregatorBuilder(String name) { + super(name, InternalReverseNested.TYPE); + } + + /** + * Set the path to use for this nested aggregation. The path must match + * the path to a nested object in the mappings. If it is not specified + * then this aggregation will go back to the root document. + */ + public ReverseNestedAggregatorBuilder path(String path) { + if (path == null) { + throw new IllegalArgumentException("[path] must not be null: [" + name + "]"); + } + this.path = path; + return this; + } + + /** + * Get the path to use for this nested aggregation. + */ + public String path() { + return path; + } + + @Override + protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) + throws IOException { + return new ReverseNestedAggregatorFactory(name, type, path, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + if (path != null) { + builder.field(ReverseNestedAggregator.PATH_FIELD.getPreferredName(), path); + } + builder.endObject(); + return builder; + } + + @Override + protected ReverseNestedAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { + ReverseNestedAggregatorBuilder factory = new ReverseNestedAggregatorBuilder(name); + factory.path = in.readOptionalString(); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeOptionalString(path); + } + + @Override + protected int doHashCode() { + return Objects.hash(path); + } + + @Override + protected boolean doEquals(Object obj) { + ReverseNestedAggregatorBuilder other = (ReverseNestedAggregatorBuilder) obj; + return Objects.equals(path, other.path); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedParser.java index 16845200aad..2fe530dc172 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedParser.java @@ -35,7 +35,7 @@ public class ReverseNestedParser implements Aggregator.Parser { } @Override - public ReverseNestedAggregator.ReverseNestedAggregatorBuilder parse(String aggregationName, XContentParser parser, + public ReverseNestedAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException { String path = null; @@ -56,7 +56,7 @@ public class ReverseNestedParser implements Aggregator.Parser { } } - ReverseNestedAggregator.ReverseNestedAggregatorBuilder factory = new ReverseNestedAggregator.ReverseNestedAggregatorBuilder( + ReverseNestedAggregatorBuilder factory = new ReverseNestedAggregatorBuilder( aggregationName); if (path != null) { factory.path(path); @@ -65,7 +65,7 @@ public class ReverseNestedParser implements Aggregator.Parser { } @Override - public ReverseNestedAggregator.ReverseNestedAggregatorBuilder getFactoryPrototypes() { - return ReverseNestedAggregator.ReverseNestedAggregatorBuilder.PROTOTYPE; + public ReverseNestedAggregatorBuilder getFactoryPrototypes() { + return ReverseNestedAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java new file mode 100644 index 00000000000..7fe87b0774e --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java @@ -0,0 +1,105 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.range; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public abstract class AbstractRangeBuilder, R extends Range> + extends ValuesSourceAggregatorBuilder { + + protected final InternalRange.Factory rangeFactory; + protected List ranges = new ArrayList<>(); + protected boolean keyed = false; + + protected AbstractRangeBuilder(String name, InternalRange.Factory rangeFactory) { + super(name, rangeFactory.type(), rangeFactory.getValueSourceType(), rangeFactory.getValueType()); + this.rangeFactory = rangeFactory; + } + + public AB addRange(R range) { + if (range == null) { + throw new IllegalArgumentException("[range] must not be null: [" + name + "]"); + } + ranges.add(range); + return (AB) this; + } + + public List ranges() { + return ranges; + } + + public AB keyed(boolean keyed) { + this.keyed = keyed; + return (AB) this; + } + + public boolean keyed() { + return keyed; + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + builder.field(RangeAggregator.RANGES_FIELD.getPreferredName(), ranges); + builder.field(RangeAggregator.KEYED_FIELD.getPreferredName(), keyed); + return builder; + } + + @Override + protected AB innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) throws IOException { + AbstractRangeBuilder factory = createFactoryFromStream(name, in); + factory.keyed = in.readBoolean(); + return (AB) factory; + } + + protected abstract AbstractRangeBuilder createFactoryFromStream(String name, StreamInput in) throws IOException; + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeVInt(ranges.size()); + for (Range range : ranges) { + range.writeTo(out); + } + out.writeBoolean(keyed); + } + + @Override + protected int innerHashCode() { + return Objects.hash(ranges, keyed); + } + + @Override + protected boolean innerEquals(Object obj) { + AbstractRangeBuilder other = (AbstractRangeBuilder) obj; + return Objects.equals(ranges, other.ranges) + && Objects.equals(keyed, other.keyed); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java index 0b2dd04d982..e8c88a27c13 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregator.java @@ -31,22 +31,15 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.NonCollectingAggregator; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.bucket.BucketsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.format.ValueFormat; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueParser; @@ -400,168 +393,4 @@ public class RangeAggregator extends BucketsAggregator { } } - public static abstract class AbstractBuilder, R extends Range> - extends ValuesSourceAggregatorBuilder { - - protected final InternalRange.Factory rangeFactory; - protected List ranges = new ArrayList<>(); - protected boolean keyed = false; - - protected AbstractBuilder(String name, InternalRange.Factory rangeFactory) { - super(name, rangeFactory.type(), rangeFactory.getValueSourceType(), rangeFactory.getValueType()); - this.rangeFactory = rangeFactory; - } - - public AB addRange(R range) { - if (range == null) { - throw new IllegalArgumentException("[range] must not be null: [" + name + "]"); - } - ranges.add(range); - return (AB) this; - } - - public List ranges() { - return ranges; - } - - public AB keyed(boolean keyed) { - this.keyed = keyed; - return (AB) this; - } - - public boolean keyed() { - return keyed; - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.field(RANGES_FIELD.getPreferredName(), ranges); - builder.field(KEYED_FIELD.getPreferredName(), keyed); - return builder; - } - - @Override - protected AB innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - AbstractBuilder factory = createFactoryFromStream(name, in); - factory.keyed = in.readBoolean(); - return (AB) factory; - } - - protected abstract AbstractBuilder createFactoryFromStream(String name, StreamInput in) throws IOException; - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeVInt(ranges.size()); - for (Range range : ranges) { - range.writeTo(out); - } - out.writeBoolean(keyed); - } - - @Override - protected int innerHashCode() { - return Objects.hash(ranges, keyed); - } - - @Override - protected boolean innerEquals(Object obj) { - AbstractBuilder other = (AbstractBuilder) obj; - return Objects.equals(ranges, other.ranges) - && Objects.equals(keyed, other.keyed); - } - } - - public static class RangeAggregatorBuilder extends AbstractBuilder { - - static final RangeAggregatorBuilder PROTOTYPE = new RangeAggregatorBuilder(""); - - public RangeAggregatorBuilder(String name) { - super(name, InternalRange.FACTORY); - } - - /** - * Add a new range to this aggregation. - * - * @param key - * the key to use for this range in the response - * @param from - * the lower bound on the distances, inclusive - * @param to - * the upper bound on the distances, exclusive - */ - public RangeAggregatorBuilder addRange(String key, double from, double to) { - addRange(new Range(key, from, to)); - return this; - } - - /** - * Same as {@link #addRange(String, double, double)} but the key will be - * automatically generated based on from and - * to. - */ - public RangeAggregatorBuilder addRange(double from, double to) { - return addRange(null, from, to); - } - - /** - * Add a new range with no lower bound. - * - * @param key - * the key to use for this range in the response - * @param to - * the upper bound on the distances, exclusive - */ - public RangeAggregatorBuilder addUnboundedTo(String key, double to) { - addRange(new Range(key, null, to)); - return this; - } - - /** - * Same as {@link #addUnboundedTo(String, double)} but the key will be - * computed automatically. - */ - public RangeAggregatorBuilder addUnboundedTo(double to) { - return addUnboundedTo(null, to); - } - - /** - * Add a new range with no upper bound. - * - * @param key - * the key to use for this range in the response - * @param from - * the lower bound on the distances, inclusive - */ - public RangeAggregatorBuilder addUnboundedFrom(String key, double from) { - addRange(new Range(key, from, null)); - return this; - } - - /** - * Same as {@link #addUnboundedFrom(String, double)} but the key will be - * computed automatically. - */ - public RangeAggregatorBuilder addUnboundedFrom(double from) { - return addUnboundedFrom(null, from); - } - - @Override - protected RangeAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new RangeAggregatorFactory(name, type, config, ranges, keyed, rangeFactory, context, parent, subFactoriesBuilder, - metaData); - } - - @Override - protected RangeAggregatorBuilder createFactoryFromStream(String name, StreamInput in) throws IOException { - int size = in.readVInt(); - RangeAggregatorBuilder factory = new RangeAggregatorBuilder(name); - for (int i = 0; i < size; i++) { - factory.addRange(Range.PROTOTYPE.readFrom(in)); - } - return factory; - } - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java new file mode 100644 index 00000000000..60de6a473c2 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java @@ -0,0 +1,122 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.range; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; + +import java.io.IOException; + +public class RangeAggregatorBuilder extends AbstractRangeBuilder { + + static final RangeAggregatorBuilder PROTOTYPE = new RangeAggregatorBuilder(""); + + public RangeAggregatorBuilder(String name) { + super(name, InternalRange.FACTORY); + } + + /** + * Add a new range to this aggregation. + * + * @param key + * the key to use for this range in the response + * @param from + * the lower bound on the distances, inclusive + * @param to + * the upper bound on the distances, exclusive + */ + public RangeAggregatorBuilder addRange(String key, double from, double to) { + addRange(new Range(key, from, to)); + return this; + } + + /** + * Same as {@link #addRange(String, double, double)} but the key will be + * automatically generated based on from and + * to. + */ + public RangeAggregatorBuilder addRange(double from, double to) { + return addRange(null, from, to); + } + + /** + * Add a new range with no lower bound. + * + * @param key + * the key to use for this range in the response + * @param to + * the upper bound on the distances, exclusive + */ + public RangeAggregatorBuilder addUnboundedTo(String key, double to) { + addRange(new Range(key, null, to)); + return this; + } + + /** + * Same as {@link #addUnboundedTo(String, double)} but the key will be + * computed automatically. + */ + public RangeAggregatorBuilder addUnboundedTo(double to) { + return addUnboundedTo(null, to); + } + + /** + * Add a new range with no upper bound. + * + * @param key + * the key to use for this range in the response + * @param from + * the lower bound on the distances, inclusive + */ + public RangeAggregatorBuilder addUnboundedFrom(String key, double from) { + addRange(new Range(key, from, null)); + return this; + } + + /** + * Same as {@link #addUnboundedFrom(String, double)} but the key will be + * computed automatically. + */ + public RangeAggregatorBuilder addUnboundedFrom(double from) { + return addUnboundedFrom(null, from); + } + + @Override + protected RangeAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new RangeAggregatorFactory(name, type, config, ranges, keyed, rangeFactory, context, parent, subFactoriesBuilder, + metaData); + } + + @Override + protected RangeAggregatorBuilder createFactoryFromStream(String name, StreamInput in) throws IOException { + int size = in.readVInt(); + RangeAggregatorBuilder factory = new RangeAggregatorBuilder(name); + for (int i = 0; i < size; i++) { + factory.addRange(Range.PROTOTYPE.readFrom(in)); + } + return factory; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeParser.java index b41ae4402eb..27018b4cb12 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeParser.java @@ -51,9 +51,9 @@ public class RangeParser extends NumericValuesSourceParser { } @Override - protected RangeAggregator.AbstractBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected AbstractRangeBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - RangeAggregator.RangeAggregatorBuilder factory = new RangeAggregator.RangeAggregatorBuilder(aggregationName); + RangeAggregatorBuilder factory = new RangeAggregatorBuilder(aggregationName); @SuppressWarnings("unchecked") List ranges = (List) otherOptions.get(RangeAggregator.RANGES_FIELD); for (Range range : ranges) { @@ -94,7 +94,7 @@ public class RangeParser extends NumericValuesSourceParser { } @Override - public RangeAggregator.AbstractBuilder getFactoryPrototypes() { - return RangeAggregator.RangeAggregatorBuilder.PROTOTYPE; + public AbstractRangeBuilder getFactoryPrototypes() { + return RangeAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/date/DateRangeAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/date/DateRangeAggregatorBuilder.java index ef702c37943..abd3ad6372e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/date/DateRangeAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/date/DateRangeAggregatorBuilder.java @@ -22,8 +22,8 @@ package org.elasticsearch.search.aggregations.bucket.range.date; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.bucket.range.AbstractRangeBuilder; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator; -import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.AbstractBuilder; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; @@ -32,7 +32,7 @@ import org.joda.time.DateTime; import java.io.IOException; -public class DateRangeAggregatorBuilder extends AbstractBuilder { +public class DateRangeAggregatorBuilder extends AbstractRangeBuilder { static final DateRangeAggregatorBuilder PROTOTYPE = new DateRangeAggregatorBuilder(""); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceAggregatorBuilder.java new file mode 100644 index 00000000000..5969265f75f --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceAggregatorBuilder.java @@ -0,0 +1,246 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.range.geodistance; + +import org.elasticsearch.common.geo.GeoDistance; +import org.elasticsearch.common.geo.GeoPoint; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.unit.DistanceUnit; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.bucket.range.InternalRange; +import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator; +import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceParser.Range; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class GeoDistanceAggregatorBuilder extends ValuesSourceAggregatorBuilder { + + static final GeoDistanceAggregatorBuilder PROTOTYPE = new GeoDistanceAggregatorBuilder("", new GeoPoint()); + + private final GeoPoint origin; + private List ranges = new ArrayList<>(); + private DistanceUnit unit = DistanceUnit.DEFAULT; + private GeoDistance distanceType = GeoDistance.DEFAULT; + private boolean keyed = false; + + public GeoDistanceAggregatorBuilder(String name, GeoPoint origin) { + this(name, origin, InternalGeoDistance.FACTORY); + } + + private GeoDistanceAggregatorBuilder(String name, GeoPoint origin, + InternalRange.Factory rangeFactory) { + super(name, rangeFactory.type(), rangeFactory.getValueSourceType(), rangeFactory.getValueType()); + if (origin == null) { + throw new IllegalArgumentException("[origin] must not be null: [" + name + "]"); + } + this.origin = origin; + } + + public GeoDistanceAggregatorBuilder addRange(Range range) { + if (range == null) { + throw new IllegalArgumentException("[range] must not be null: [" + name + "]"); + } + ranges.add(range); + return this; + } + + /** + * Add a new range to this aggregation. + * + * @param key + * the key to use for this range in the response + * @param from + * the lower bound on the distances, inclusive + * @param to + * the upper bound on the distances, exclusive + */ + public GeoDistanceAggregatorBuilder addRange(String key, double from, double to) { + ranges.add(new Range(key, from, to)); + return this; + } + + /** + * Same as {@link #addRange(String, double, double)} but the key will be + * automatically generated based on from and + * to. + */ + public GeoDistanceAggregatorBuilder addRange(double from, double to) { + return addRange(null, from, to); + } + + /** + * Add a new range with no lower bound. + * + * @param key + * the key to use for this range in the response + * @param to + * the upper bound on the distances, exclusive + */ + public GeoDistanceAggregatorBuilder addUnboundedTo(String key, double to) { + ranges.add(new Range(key, null, to)); + return this; + } + + /** + * Same as {@link #addUnboundedTo(String, double)} but the key will be + * computed automatically. + */ + public GeoDistanceAggregatorBuilder addUnboundedTo(double to) { + return addUnboundedTo(null, to); + } + + /** + * Add a new range with no upper bound. + * + * @param key + * the key to use for this range in the response + * @param from + * the lower bound on the distances, inclusive + */ + public GeoDistanceAggregatorBuilder addUnboundedFrom(String key, double from) { + addRange(new Range(key, from, null)); + return this; + } + + /** + * Same as {@link #addUnboundedFrom(String, double)} but the key will be + * computed automatically. + */ + public GeoDistanceAggregatorBuilder addUnboundedFrom(double from) { + return addUnboundedFrom(null, from); + } + + public List range() { + return ranges; + } + + @Override + public String getWriteableName() { + return InternalGeoDistance.TYPE.name(); + } + + public GeoDistanceAggregatorBuilder unit(DistanceUnit unit) { + if (unit == null) { + throw new IllegalArgumentException("[unit] must not be null: [" + name + "]"); + } + this.unit = unit; + return this; + } + + public DistanceUnit unit() { + return unit; + } + + public GeoDistanceAggregatorBuilder distanceType(GeoDistance distanceType) { + if (distanceType == null) { + throw new IllegalArgumentException("[distanceType] must not be null: [" + name + "]"); + } + this.distanceType = distanceType; + return this; + } + + public GeoDistance distanceType() { + return distanceType; + } + + public GeoDistanceAggregatorBuilder keyed(boolean keyed) { + this.keyed = keyed; + return this; + } + + public boolean keyed() { + return keyed; + } + + @Override + protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, + ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) + throws IOException { + return new GeoDistanceRangeAggregatorFactory(name, type, config, origin, ranges, unit, distanceType, keyed, context, parent, + subFactoriesBuilder, metaData); + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + builder.field(GeoDistanceParser.ORIGIN_FIELD.getPreferredName(), origin); + builder.field(RangeAggregator.RANGES_FIELD.getPreferredName(), ranges); + builder.field(RangeAggregator.KEYED_FIELD.getPreferredName(), keyed); + builder.field(GeoDistanceParser.UNIT_FIELD.getPreferredName(), unit); + builder.field(GeoDistanceParser.DISTANCE_TYPE_FIELD.getPreferredName(), distanceType); + return builder; + } + + @Override + protected GeoDistanceAggregatorBuilder innerReadFrom( + String name, ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in) throws IOException { + GeoPoint origin = new GeoPoint(in.readDouble(), in.readDouble()); + int size = in.readVInt(); + GeoDistanceAggregatorBuilder factory = new GeoDistanceAggregatorBuilder(name, origin); + for (int i = 0; i < size; i++) { + factory.addRange(Range.PROTOTYPE.readFrom(in)); + } + factory.keyed = in.readBoolean(); + factory.distanceType = GeoDistance.readGeoDistanceFrom(in); + factory.unit = DistanceUnit.readDistanceUnit(in); + return factory; + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeDouble(origin.lat()); + out.writeDouble(origin.lon()); + out.writeVInt(ranges.size()); + for (Range range : ranges) { + range.writeTo(out); + } + out.writeBoolean(keyed); + distanceType.writeTo(out); + DistanceUnit.writeDistanceUnit(out, unit); + } + + @Override + protected int innerHashCode() { + return Objects.hash(origin, ranges, keyed, distanceType, unit); + } + + @Override + protected boolean innerEquals(Object obj) { + GeoDistanceAggregatorBuilder other = (GeoDistanceAggregatorBuilder) obj; + return Objects.equals(origin, other.origin) + && Objects.equals(ranges, other.ranges) + && Objects.equals(keyed, other.keyed) + && Objects.equals(distanceType, other.distanceType) + && Objects.equals(unit, other.unit); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceParser.java index 477125ba752..670e4dda0d6 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceParser.java @@ -25,37 +25,27 @@ import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.DistanceUnit; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser.Token; -import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; -import org.elasticsearch.search.aggregations.bucket.range.InternalRange; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator; import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.GeoPointValuesSourceParser; -import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.GeoPointParser; import org.elasticsearch.search.aggregations.support.ValueType; -import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Objects; /** * */ public class GeoDistanceParser extends GeoPointValuesSourceParser { - private static final ParseField ORIGIN_FIELD = new ParseField("origin", "center", "point", "por"); - private static final ParseField UNIT_FIELD = new ParseField("unit"); - private static final ParseField DISTANCE_TYPE_FIELD = new ParseField("distance_type"); + static final ParseField ORIGIN_FIELD = new ParseField("origin", "center", "point", "por"); + static final ParseField UNIT_FIELD = new ParseField("unit"); + static final ParseField DISTANCE_TYPE_FIELD = new ParseField("distance_type"); private GeoPointParser geoPointParser = new GeoPointParser(InternalGeoDistance.TYPE, ORIGIN_FIELD); @@ -192,208 +182,6 @@ public class GeoDistanceParser extends GeoPointValuesSourceParser { return false; } - public static class GeoDistanceAggregatorBuilder extends ValuesSourceAggregatorBuilder { - - static final GeoDistanceAggregatorBuilder PROTOTYPE = new GeoDistanceAggregatorBuilder("", new GeoPoint()); - - private final GeoPoint origin; - private List ranges = new ArrayList<>(); - private DistanceUnit unit = DistanceUnit.DEFAULT; - private GeoDistance distanceType = GeoDistance.DEFAULT; - private boolean keyed = false; - - public GeoDistanceAggregatorBuilder(String name, GeoPoint origin) { - this(name, origin, InternalGeoDistance.FACTORY); - } - - private GeoDistanceAggregatorBuilder(String name, GeoPoint origin, - InternalRange.Factory rangeFactory) { - super(name, rangeFactory.type(), rangeFactory.getValueSourceType(), rangeFactory.getValueType()); - if (origin == null) { - throw new IllegalArgumentException("[origin] must not be null: [" + name + "]"); - } - this.origin = origin; - } - - public GeoDistanceAggregatorBuilder addRange(Range range) { - if (range == null) { - throw new IllegalArgumentException("[range] must not be null: [" + name + "]"); - } - ranges.add(range); - return this; - } - - /** - * Add a new range to this aggregation. - * - * @param key - * the key to use for this range in the response - * @param from - * the lower bound on the distances, inclusive - * @param to - * the upper bound on the distances, exclusive - */ - public GeoDistanceAggregatorBuilder addRange(String key, double from, double to) { - ranges.add(new Range(key, from, to)); - return this; - } - - /** - * Same as {@link #addRange(String, double, double)} but the key will be - * automatically generated based on from and - * to. - */ - public GeoDistanceAggregatorBuilder addRange(double from, double to) { - return addRange(null, from, to); - } - - /** - * Add a new range with no lower bound. - * - * @param key - * the key to use for this range in the response - * @param to - * the upper bound on the distances, exclusive - */ - public GeoDistanceAggregatorBuilder addUnboundedTo(String key, double to) { - ranges.add(new Range(key, null, to)); - return this; - } - - /** - * Same as {@link #addUnboundedTo(String, double)} but the key will be - * computed automatically. - */ - public GeoDistanceAggregatorBuilder addUnboundedTo(double to) { - return addUnboundedTo(null, to); - } - - /** - * Add a new range with no upper bound. - * - * @param key - * the key to use for this range in the response - * @param from - * the lower bound on the distances, inclusive - */ - public GeoDistanceAggregatorBuilder addUnboundedFrom(String key, double from) { - addRange(new Range(key, from, null)); - return this; - } - - /** - * Same as {@link #addUnboundedFrom(String, double)} but the key will be - * computed automatically. - */ - public GeoDistanceAggregatorBuilder addUnboundedFrom(double from) { - return addUnboundedFrom(null, from); - } - - public List range() { - return ranges; - } - - @Override - public String getWriteableName() { - return InternalGeoDistance.TYPE.name(); - } - - public GeoDistanceAggregatorBuilder unit(DistanceUnit unit) { - if (unit == null) { - throw new IllegalArgumentException("[unit] must not be null: [" + name + "]"); - } - this.unit = unit; - return this; - } - - public DistanceUnit unit() { - return unit; - } - - public GeoDistanceAggregatorBuilder distanceType(GeoDistance distanceType) { - if (distanceType == null) { - throw new IllegalArgumentException("[distanceType] must not be null: [" + name + "]"); - } - this.distanceType = distanceType; - return this; - } - - public GeoDistance distanceType() { - return distanceType; - } - - public GeoDistanceAggregatorBuilder keyed(boolean keyed) { - this.keyed = keyed; - return this; - } - - public boolean keyed() { - return keyed; - } - - @Override - protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, - ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) - throws IOException { - return new GeoDistanceRangeAggregatorFactory(name, type, config, origin, ranges, unit, distanceType, keyed, context, parent, - subFactoriesBuilder, metaData); - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.field(ORIGIN_FIELD.getPreferredName(), origin); - builder.field(RangeAggregator.RANGES_FIELD.getPreferredName(), ranges); - builder.field(RangeAggregator.KEYED_FIELD.getPreferredName(), keyed); - builder.field(UNIT_FIELD.getPreferredName(), unit); - builder.field(DISTANCE_TYPE_FIELD.getPreferredName(), distanceType); - return builder; - } - - @Override - protected GeoDistanceAggregatorBuilder innerReadFrom( - String name, ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in) throws IOException { - GeoPoint origin = new GeoPoint(in.readDouble(), in.readDouble()); - int size = in.readVInt(); - GeoDistanceAggregatorBuilder factory = new GeoDistanceAggregatorBuilder(name, origin); - for (int i = 0; i < size; i++) { - factory.addRange(Range.PROTOTYPE.readFrom(in)); - } - factory.keyed = in.readBoolean(); - factory.distanceType = GeoDistance.readGeoDistanceFrom(in); - factory.unit = DistanceUnit.readDistanceUnit(in); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeDouble(origin.lat()); - out.writeDouble(origin.lon()); - out.writeVInt(ranges.size()); - for (Range range : ranges) { - range.writeTo(out); - } - out.writeBoolean(keyed); - distanceType.writeTo(out); - DistanceUnit.writeDistanceUnit(out, unit); - } - - @Override - protected int innerHashCode() { - return Objects.hash(origin, ranges, keyed, distanceType, unit); - } - - @Override - protected boolean innerEquals(Object obj) { - GeoDistanceAggregatorBuilder other = (GeoDistanceAggregatorBuilder) obj; - return Objects.equals(origin, other.origin) - && Objects.equals(ranges, other.ranges) - && Objects.equals(keyed, other.keyed) - && Objects.equals(distanceType, other.distanceType) - && Objects.equals(unit, other.unit); - } - - } - @Override public GeoDistanceAggregatorBuilder getFactoryPrototypes() { return GeoDistanceAggregatorBuilder.PROTOTYPE; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ipv4/IPv4RangeAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ipv4/IPv4RangeAggregatorBuilder.java index 89b9e394fb1..40c93eaebee 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ipv4/IPv4RangeAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ipv4/IPv4RangeAggregatorBuilder.java @@ -28,8 +28,8 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.bucket.range.AbstractRangeBuilder; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator; -import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.AbstractBuilder; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; @@ -37,7 +37,7 @@ import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import java.io.IOException; import java.util.Objects; -public class IPv4RangeAggregatorBuilder extends AbstractBuilder { +public class IPv4RangeAggregatorBuilder extends AbstractRangeBuilder { static final IPv4RangeAggregatorBuilder PROTOTYPE = new IPv4RangeAggregatorBuilder(""); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorBuilder.java new file mode 100644 index 00000000000..d7e44ba8254 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorBuilder.java @@ -0,0 +1,154 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.sampler; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.InternalAggregation.Type; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; + +import java.io.IOException; +import java.util.Objects; + +public class DiversifiedAggregatorBuilder extends ValuesSourceAggregatorBuilder { + + public static final Type TYPE = new Type("diversified_sampler"); + + static final DiversifiedAggregatorBuilder PROTOTYPE = new DiversifiedAggregatorBuilder(""); + + public static final int MAX_DOCS_PER_VALUE_DEFAULT = 1; + + private int shardSize = SamplerAggregatorBuilder.DEFAULT_SHARD_SAMPLE_SIZE; + private int maxDocsPerValue = MAX_DOCS_PER_VALUE_DEFAULT; + private String executionHint = null; + + public DiversifiedAggregatorBuilder(String name) { + super(name, TYPE, ValuesSourceType.ANY, null); + } + + /** + * Set the max num docs to be returned from each shard. + */ + public DiversifiedAggregatorBuilder shardSize(int shardSize) { + if (shardSize < 0) { + throw new IllegalArgumentException( + "[shardSize] must be greater than or equal to 0. Found [" + shardSize + "] in [" + name + "]"); + } + this.shardSize = shardSize; + return this; + } + + /** + * Get the max num docs to be returned from each shard. + */ + public int shardSize() { + return shardSize; + } + + /** + * Set the max num docs to be returned per value. + */ + public DiversifiedAggregatorBuilder maxDocsPerValue(int maxDocsPerValue) { + if (maxDocsPerValue < 0) { + throw new IllegalArgumentException( + "[maxDocsPerValue] must be greater than or equal to 0. Found [" + maxDocsPerValue + "] in [" + name + "]"); + } + this.maxDocsPerValue = maxDocsPerValue; + return this; + } + + /** + * Get the max num docs to be returned per value. + */ + public int maxDocsPerValue() { + return maxDocsPerValue; + } + + /** + * Set the execution hint. + */ + public DiversifiedAggregatorBuilder executionHint(String executionHint) { + this.executionHint = executionHint; + return this; + } + + /** + * Get the execution hint. + */ + public String executionHint() { + return executionHint; + } + + @Override + protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, + ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new DiversifiedAggregatorFactory(name, TYPE, config, shardSize, maxDocsPerValue, executionHint, context, parent, + subFactoriesBuilder, metaData); + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + builder.field(SamplerAggregator.SHARD_SIZE_FIELD.getPreferredName(), shardSize); + builder.field(SamplerAggregator.MAX_DOCS_PER_VALUE_FIELD.getPreferredName(), maxDocsPerValue); + if (executionHint != null) { + builder.field(SamplerAggregator.EXECUTION_HINT_FIELD.getPreferredName(), executionHint); + } + return builder; + } + + @Override + protected DiversifiedAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) throws IOException { + DiversifiedAggregatorBuilder factory = new DiversifiedAggregatorBuilder(name); + factory.shardSize = in.readVInt(); + factory.maxDocsPerValue = in.readVInt(); + factory.executionHint = in.readOptionalString(); + return factory; + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeVInt(shardSize); + out.writeVInt(maxDocsPerValue); + out.writeOptionalString(executionHint); + } + + @Override + protected int innerHashCode() { + return Objects.hash(shardSize, maxDocsPerValue, executionHint); + } + + @Override + protected boolean innerEquals(Object obj) { + DiversifiedAggregatorBuilder other = (DiversifiedAggregatorBuilder) obj; + return Objects.equals(shardSize, other.shardSize) + && Objects.equals(maxDocsPerValue, other.maxDocsPerValue) + && Objects.equals(executionHint, other.executionHint); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedSamplerParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedSamplerParser.java index ba46c3a5b30..79ac7ba7ed5 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedSamplerParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedSamplerParser.java @@ -41,13 +41,13 @@ public class DiversifiedSamplerParser extends AnyValuesSourceParser { @Override public String type() { - return SamplerAggregator.DiversifiedAggregatorBuilder.TYPE.name(); + return DiversifiedAggregatorBuilder.TYPE.name(); } @Override - protected SamplerAggregator.DiversifiedAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected DiversifiedAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - SamplerAggregator.DiversifiedAggregatorBuilder factory = new SamplerAggregator.DiversifiedAggregatorBuilder(aggregationName); + DiversifiedAggregatorBuilder factory = new DiversifiedAggregatorBuilder(aggregationName); Integer shardSize = (Integer) otherOptions.get(SamplerAggregator.SHARD_SIZE_FIELD); if (shardSize != null) { factory.shardSize(shardSize); @@ -88,7 +88,7 @@ public class DiversifiedSamplerParser extends AnyValuesSourceParser { @Override public AggregatorBuilder getFactoryPrototypes() { - return SamplerAggregator.DiversifiedAggregatorBuilder.PROTOTYPE; + return DiversifiedAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregator.java index 59b89133b87..cec2c4577df 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregator.java @@ -21,34 +21,22 @@ package org.elasticsearch.search.aggregations.bucket.sampler; import org.apache.lucene.index.LeafReaderContext; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.InternalAggregation; -import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.LeafBucketCollector; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.bucket.BestDocsDeferringCollector; import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector; import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; + import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Objects; /** * Aggregate on only the top-scoring docs on a shard. @@ -191,189 +179,6 @@ public class SamplerAggregator extends SingleBucketAggregator { return new InternalSampler(name, 0, buildEmptySubAggregations(), pipelineAggregators(), metaData()); } - public static class SamplerAggregatorBuilder extends AggregatorBuilder { - - static final SamplerAggregatorBuilder PROTOTYPE = new SamplerAggregatorBuilder(""); - - public static final int DEFAULT_SHARD_SAMPLE_SIZE = 100; - - private int shardSize = DEFAULT_SHARD_SAMPLE_SIZE; - - public SamplerAggregatorBuilder(String name) { - super(name, InternalSampler.TYPE); - } - - /** - * Set the max num docs to be returned from each shard. - */ - public SamplerAggregatorBuilder shardSize(int shardSize) { - this.shardSize = shardSize; - return this; - } - - /** - * Get the max num docs to be returned from each shard. - */ - public int shardSize() { - return shardSize; - } - - @Override - protected SamplerAggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) - throws IOException { - return new SamplerAggregatorFactory(name, type, shardSize, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.field(SHARD_SIZE_FIELD.getPreferredName(), shardSize); - builder.endObject(); - return builder; - } - - @Override - protected SamplerAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { - SamplerAggregatorBuilder factory = new SamplerAggregatorBuilder(name); - factory.shardSize = in.readVInt(); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeVInt(shardSize); - } - - @Override - protected int doHashCode() { - return Objects.hash(shardSize); - } - - @Override - protected boolean doEquals(Object obj) { - SamplerAggregatorBuilder other = (SamplerAggregatorBuilder) obj; - return Objects.equals(shardSize, other.shardSize); - } - - } - - public static class DiversifiedAggregatorBuilder extends ValuesSourceAggregatorBuilder { - - public static final Type TYPE = new Type("diversified_sampler"); - - static final DiversifiedAggregatorBuilder PROTOTYPE = new DiversifiedAggregatorBuilder(""); - - public static final int MAX_DOCS_PER_VALUE_DEFAULT = 1; - - private int shardSize = SamplerAggregatorBuilder.DEFAULT_SHARD_SAMPLE_SIZE; - private int maxDocsPerValue = MAX_DOCS_PER_VALUE_DEFAULT; - private String executionHint = null; - - public DiversifiedAggregatorBuilder(String name) { - super(name, TYPE, ValuesSourceType.ANY, null); - } - - /** - * Set the max num docs to be returned from each shard. - */ - public DiversifiedAggregatorBuilder shardSize(int shardSize) { - if (shardSize < 0) { - throw new IllegalArgumentException( - "[shardSize] must be greater than or equal to 0. Found [" + shardSize + "] in [" + name + "]"); - } - this.shardSize = shardSize; - return this; - } - - /** - * Get the max num docs to be returned from each shard. - */ - public int shardSize() { - return shardSize; - } - - /** - * Set the max num docs to be returned per value. - */ - public DiversifiedAggregatorBuilder maxDocsPerValue(int maxDocsPerValue) { - if (maxDocsPerValue < 0) { - throw new IllegalArgumentException( - "[maxDocsPerValue] must be greater than or equal to 0. Found [" + maxDocsPerValue + "] in [" + name + "]"); - } - this.maxDocsPerValue = maxDocsPerValue; - return this; - } - - /** - * Get the max num docs to be returned per value. - */ - public int maxDocsPerValue() { - return maxDocsPerValue; - } - - /** - * Set the execution hint. - */ - public DiversifiedAggregatorBuilder executionHint(String executionHint) { - this.executionHint = executionHint; - return this; - } - - /** - * Get the execution hint. - */ - public String executionHint() { - return executionHint; - } - - @Override - protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context, - ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new DiversifiedAggregatorFactory(name, TYPE, config, shardSize, maxDocsPerValue, executionHint, context, parent, - subFactoriesBuilder, metaData); - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.field(SHARD_SIZE_FIELD.getPreferredName(), shardSize); - builder.field(MAX_DOCS_PER_VALUE_FIELD.getPreferredName(), maxDocsPerValue); - if (executionHint != null) { - builder.field(EXECUTION_HINT_FIELD.getPreferredName(), executionHint); - } - return builder; - } - - @Override - protected DiversifiedAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - DiversifiedAggregatorBuilder factory = new DiversifiedAggregatorBuilder(name); - factory.shardSize = in.readVInt(); - factory.maxDocsPerValue = in.readVInt(); - factory.executionHint = in.readOptionalString(); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeVInt(shardSize); - out.writeVInt(maxDocsPerValue); - out.writeOptionalString(executionHint); - } - - @Override - protected int innerHashCode() { - return Objects.hash(shardSize, maxDocsPerValue, executionHint); - } - - @Override - protected boolean innerEquals(Object obj) { - DiversifiedAggregatorBuilder other = (DiversifiedAggregatorBuilder) obj; - return Objects.equals(shardSize, other.shardSize) - && Objects.equals(maxDocsPerValue, other.maxDocsPerValue) - && Objects.equals(executionHint, other.executionHint); - } - } - @Override protected LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException { if (bdd == null) { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregatorBuilder.java new file mode 100644 index 00000000000..d00ea80ae29 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregatorBuilder.java @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.bucket.sampler; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; + +import java.io.IOException; +import java.util.Objects; + +public class SamplerAggregatorBuilder extends AggregatorBuilder { + + static final SamplerAggregatorBuilder PROTOTYPE = new SamplerAggregatorBuilder(""); + + public static final int DEFAULT_SHARD_SAMPLE_SIZE = 100; + + private int shardSize = DEFAULT_SHARD_SAMPLE_SIZE; + + public SamplerAggregatorBuilder(String name) { + super(name, InternalSampler.TYPE); + } + + /** + * Set the max num docs to be returned from each shard. + */ + public SamplerAggregatorBuilder shardSize(int shardSize) { + this.shardSize = shardSize; + return this; + } + + /** + * Get the max num docs to be returned from each shard. + */ + public int shardSize() { + return shardSize; + } + + @Override + protected SamplerAggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder) + throws IOException { + return new SamplerAggregatorFactory(name, type, shardSize, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.field(SamplerAggregator.SHARD_SIZE_FIELD.getPreferredName(), shardSize); + builder.endObject(); + return builder; + } + + @Override + protected SamplerAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { + SamplerAggregatorBuilder factory = new SamplerAggregatorBuilder(name); + factory.shardSize = in.readVInt(); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeVInt(shardSize); + } + + @Override + protected int doHashCode() { + return Objects.hash(shardSize); + } + + @Override + protected boolean doEquals(Object obj) { + SamplerAggregatorBuilder other = (SamplerAggregatorBuilder) obj; + return Objects.equals(shardSize, other.shardSize); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java index 0e834373f82..593ab28580b 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java @@ -36,7 +36,7 @@ public class SamplerParser implements Aggregator.Parser { } @Override - public SamplerAggregator.SamplerAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) + public SamplerAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException { XContentParser.Token token; @@ -59,7 +59,7 @@ public class SamplerParser implements Aggregator.Parser { } } - SamplerAggregator.SamplerAggregatorBuilder factory = new SamplerAggregator.SamplerAggregatorBuilder(aggregationName); + SamplerAggregatorBuilder factory = new SamplerAggregatorBuilder(aggregationName); if (shardSize != null) { factory.shardSize(shardSize); } @@ -67,8 +67,8 @@ public class SamplerParser implements Aggregator.Parser { } @Override - public SamplerAggregator.SamplerAggregatorBuilder getFactoryPrototypes() { - return SamplerAggregator.SamplerAggregatorBuilder.PROTOTYPE; + public SamplerAggregatorBuilder getFactoryPrototypes() { + return SamplerAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java index c0faba8f5b1..34312cbb696 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java @@ -19,29 +19,19 @@ package org.elasticsearch.search.aggregations.metrics.avg; import org.apache.lucene.index.LeafReaderContext; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.LongArray; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; @@ -120,47 +110,6 @@ public class AvgAggregator extends NumericMetricsAggregator.SingleValue { return new InternalAvg(name, 0.0, 0L, formatter, pipelineAggregators(), metaData()); } - public static class AvgAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final AvgAggregatorBuilder PROTOTYPE = new AvgAggregatorBuilder(""); - - public AvgAggregatorBuilder(String name) { - super(name, InternalAvg.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); - } - - @Override - protected AvgAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new AvgAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected AvgAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new AvgAggregator.AvgAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(Object obj) { - return true; - } - } - @Override public void doClose() { Releasables.close(counts, sums); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorBuilder.java new file mode 100644 index 00000000000..351069f79d9 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorBuilder.java @@ -0,0 +1,77 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.avg; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.ToXContent.Params; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; + +import java.io.IOException; + +public class AvgAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { + + static final AvgAggregatorBuilder PROTOTYPE = new AvgAggregatorBuilder(""); + + public AvgAggregatorBuilder(String name) { + super(name, InternalAvg.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected AvgAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new AvgAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected AvgAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) { + return new AvgAggregatorBuilder(name); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(Object obj) { + return true; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgParser.java index ee4c2d309a3..f51e4070fd7 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgParser.java @@ -49,14 +49,14 @@ public class AvgParser extends NumericValuesSourceParser { } @Override - protected AvgAggregator.AvgAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected AvgAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - return new AvgAggregator.AvgAggregatorBuilder(aggregationName); + return new AvgAggregatorBuilder(aggregationName); } @Override - public AvgAggregator.AvgAggregatorBuilder getFactoryPrototypes() { - return AvgAggregator.AvgAggregatorBuilder.PROTOTYPE; + public AvgAggregatorBuilder getFactoryPrototypes() { + return AvgAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregator.java index 889c4b90797..57e30fd58bd 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregator.java @@ -22,31 +22,22 @@ package org.elasticsearch.search.aggregations.metrics.geobounds; import org.apache.lucene.index.LeafReaderContext; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.geo.GeoPoint; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.DoubleArray; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.MultiGeoPointValues; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.metrics.MetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; + import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Objects; public final class GeoBoundsAggregator extends MetricsAggregator { @@ -175,68 +166,4 @@ public final class GeoBoundsAggregator extends MetricsAggregator { public void doClose() { Releasables.close(tops, bottoms, posLefts, posRights, negLefts, negRights); } - - public static class GeoBoundsAggregatorBuilder - extends ValuesSourceAggregatorBuilder { - - static final GeoBoundsAggregatorBuilder PROTOTYPE = new GeoBoundsAggregatorBuilder(""); - - private boolean wrapLongitude = true; - - public GeoBoundsAggregatorBuilder(String name) { - super(name, InternalGeoBounds.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); - } - - /** - * Set whether to wrap longitudes. Defaults to true. - */ - public GeoBoundsAggregatorBuilder wrapLongitude(boolean wrapLongitude) { - this.wrapLongitude = wrapLongitude; - return this; - } - - /** - * Get whether to wrap longitudes. - */ - public boolean wrapLongitude() { - return wrapLongitude; - } - - @Override - protected GeoBoundsAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new GeoBoundsAggregatorFactory(name, type, config, wrapLongitude, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected GeoBoundsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - GeoBoundsAggregatorBuilder factory = new GeoBoundsAggregatorBuilder(name); - factory.wrapLongitude = in.readBoolean(); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeBoolean(wrapLongitude); - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.field(WRAP_LONGITUDE_FIELD.getPreferredName(), wrapLongitude); - return builder; - } - - @Override - protected int innerHashCode() { - return Objects.hash(wrapLongitude); - } - - @Override - protected boolean innerEquals(Object obj) { - GeoBoundsAggregatorBuilder other = (GeoBoundsAggregatorBuilder) obj; - return Objects.equals(wrapLongitude, other.wrapLongitude); - } - - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregatorBuilder.java new file mode 100644 index 00000000000..511f295af0c --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregatorBuilder.java @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.geobounds; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import java.io.IOException; +import java.util.Objects; + +public class GeoBoundsAggregatorBuilder extends ValuesSourceAggregatorBuilder { + + static final GeoBoundsAggregatorBuilder PROTOTYPE = new GeoBoundsAggregatorBuilder(""); + + private boolean wrapLongitude = true; + + public GeoBoundsAggregatorBuilder(String name) { + super(name, InternalGeoBounds.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); + } + + /** + * Set whether to wrap longitudes. Defaults to true. + */ + public GeoBoundsAggregatorBuilder wrapLongitude(boolean wrapLongitude) { + this.wrapLongitude = wrapLongitude; + return this; + } + + /** + * Get whether to wrap longitudes. + */ + public boolean wrapLongitude() { + return wrapLongitude; + } + + @Override + protected GeoBoundsAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new GeoBoundsAggregatorFactory(name, type, config, wrapLongitude, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected GeoBoundsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) throws IOException { + GeoBoundsAggregatorBuilder factory = new GeoBoundsAggregatorBuilder(name); + factory.wrapLongitude = in.readBoolean(); + return factory; + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeBoolean(wrapLongitude); + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + builder.field(GeoBoundsAggregator.WRAP_LONGITUDE_FIELD.getPreferredName(), wrapLongitude); + return builder; + } + + @Override + protected int innerHashCode() { + return Objects.hash(wrapLongitude); + } + + @Override + protected boolean innerEquals(Object obj) { + GeoBoundsAggregatorBuilder other = (GeoBoundsAggregatorBuilder) obj; + return Objects.equals(wrapLongitude, other.wrapLongitude); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsParser.java index 8070b24f255..7da136200ca 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsParser.java @@ -42,9 +42,9 @@ public class GeoBoundsParser extends GeoPointValuesSourceParser { } @Override - protected GeoBoundsAggregator.GeoBoundsAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected GeoBoundsAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - GeoBoundsAggregator.GeoBoundsAggregatorBuilder factory = new GeoBoundsAggregator.GeoBoundsAggregatorBuilder(aggregationName); + GeoBoundsAggregatorBuilder factory = new GeoBoundsAggregatorBuilder(aggregationName); Boolean wrapLongitude = (Boolean) otherOptions.get(GeoBoundsAggregator.WRAP_LONGITUDE_FIELD); if (wrapLongitude != null) { factory.wrapLongitude(wrapLongitude); @@ -65,8 +65,8 @@ public class GeoBoundsParser extends GeoPointValuesSourceParser { } @Override - public GeoBoundsAggregator.GeoBoundsAggregatorBuilder getFactoryPrototypes() { - return GeoBoundsAggregator.GeoBoundsAggregatorBuilder.PROTOTYPE; + public GeoBoundsAggregatorBuilder getFactoryPrototypes() { + return GeoBoundsAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregator.java index 4eb04f84b21..472670d366e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregator.java @@ -22,27 +22,19 @@ package org.elasticsearch.search.aggregations.metrics.geocentroid; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.spatial.util.GeoEncodingUtils; import org.elasticsearch.common.geo.GeoPoint; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.LongArray; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.MultiGeoPointValues; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.metrics.MetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; + import java.io.IOException; import java.util.List; import java.util.Map; @@ -126,46 +118,4 @@ public final class GeoCentroidAggregator extends MetricsAggregator { public void doClose() { Releasables.close(centroids, counts); } - - public static class GeoCentroidAggregatorBuilder - extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final GeoCentroidAggregatorBuilder PROTOTYPE = new GeoCentroidAggregatorBuilder(""); - - public GeoCentroidAggregatorBuilder(String name) { - super(name, InternalGeoCentroid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); - } - - @Override - protected GeoCentroidAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new GeoCentroidAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected GeoCentroidAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - return new GeoCentroidAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(Object obj) { - return true; - } - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregatorBuilder.java new file mode 100644 index 00000000000..634f1228fb4 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregatorBuilder.java @@ -0,0 +1,78 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.geocentroid; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.ToXContent.Params; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.search.aggregations.support.ValuesSource.GeoPoint; + +import java.io.IOException; + +public class GeoCentroidAggregatorBuilder + extends ValuesSourceAggregatorBuilder.LeafOnly { + + static final GeoCentroidAggregatorBuilder PROTOTYPE = new GeoCentroidAggregatorBuilder(""); + + public GeoCentroidAggregatorBuilder(String name) { + super(name, InternalGeoCentroid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); + } + + @Override + protected GeoCentroidAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new GeoCentroidAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected GeoCentroidAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) throws IOException { + return new GeoCentroidAggregatorBuilder(name); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(Object obj) { + return true; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidParser.java index 30a6ce8fdb6..d520b263012 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidParser.java @@ -51,13 +51,13 @@ public class GeoCentroidParser extends GeoPointValuesSourceParser { } @Override - protected GeoCentroidAggregator.GeoCentroidAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected GeoCentroidAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - return new GeoCentroidAggregator.GeoCentroidAggregatorBuilder(aggregationName); + return new GeoCentroidAggregatorBuilder(aggregationName); } @Override - public GeoCentroidAggregator.GeoCentroidAggregatorBuilder getFactoryPrototypes() { - return GeoCentroidAggregator.GeoCentroidAggregatorBuilder.PROTOTYPE; + public GeoCentroidAggregatorBuilder getFactoryPrototypes() { + return GeoCentroidAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java index 56764dd9cf5..d207fdd53ae 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java @@ -19,30 +19,20 @@ package org.elasticsearch.search.aggregations.metrics.max; import org.apache.lucene.index.LeafReaderContext; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.DoubleArray; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.search.MultiValueMode; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; @@ -122,48 +112,6 @@ public class MaxAggregator extends NumericMetricsAggregator.SingleValue { return new InternalMax(name, Double.NEGATIVE_INFINITY, formatter, pipelineAggregators(), metaData()); } - public static class MaxAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final MaxAggregatorBuilder PROTOTYPE = new MaxAggregatorBuilder(""); - - public MaxAggregatorBuilder(String name) { - super(name, InternalMax.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); - } - - @Override - protected MaxAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new MaxAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected MaxAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new MaxAggregator.MaxAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(Object obj) { - return true; - } - - } - @Override public void doClose() { Releasables.close(maxes); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java new file mode 100644 index 00000000000..2eb86535ca0 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java @@ -0,0 +1,78 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.max; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.ToXContent.Params; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; + +import java.io.IOException; + +public class MaxAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { + + static final MaxAggregatorBuilder PROTOTYPE = new MaxAggregatorBuilder(""); + + public MaxAggregatorBuilder(String name) { + super(name, InternalMax.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected MaxAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new MaxAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected MaxAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) { + return new MaxAggregatorBuilder(name); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(Object obj) { + return true; + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java index 4c6bdaf82b7..50b622f9019 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java @@ -49,14 +49,14 @@ public class MaxParser extends NumericValuesSourceParser { } @Override - protected MaxAggregator.MaxAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected MaxAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - return new MaxAggregator.MaxAggregatorBuilder(aggregationName); + return new MaxAggregatorBuilder(aggregationName); } @Override - public MaxAggregator.MaxAggregatorBuilder getFactoryPrototypes() { - return MaxAggregator.MaxAggregatorBuilder.PROTOTYPE; + public MaxAggregatorBuilder getFactoryPrototypes() { + return MaxAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java index 81a78f60ab3..80aacff9312 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java @@ -19,30 +19,20 @@ package org.elasticsearch.search.aggregations.metrics.min; import org.apache.lucene.index.LeafReaderContext; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.DoubleArray; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.search.MultiValueMode; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; @@ -121,47 +111,6 @@ public class MinAggregator extends NumericMetricsAggregator.SingleValue { return new InternalMin(name, Double.POSITIVE_INFINITY, formatter, pipelineAggregators(), metaData()); } - public static class MinAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final MinAggregatorBuilder PROTOTYPE = new MinAggregatorBuilder(""); - - public MinAggregatorBuilder(String name) { - super(name, InternalMin.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); - } - - @Override - protected MinAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new MinAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected MinAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new MinAggregator.MinAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(Object obj) { - return true; - } - } - @Override public void doClose() { Releasables.close(mins); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java new file mode 100644 index 00000000000..186c38d26d3 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java @@ -0,0 +1,77 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.min; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.ToXContent.Params; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; + +import java.io.IOException; + +public class MinAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { + + static final MinAggregatorBuilder PROTOTYPE = new MinAggregatorBuilder(""); + + public MinAggregatorBuilder(String name) { + super(name, InternalMin.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected MinAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new MinAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected MinAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) { + return new MinAggregatorBuilder(name); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(Object obj) { + return true; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java index 9a18eb4e689..f7a3a04c6ae 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java @@ -50,13 +50,13 @@ public class MinParser extends NumericValuesSourceParser { } @Override - protected MinAggregator.MinAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected MinAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - return new MinAggregator.MinAggregatorBuilder(aggregationName); + return new MinAggregatorBuilder(aggregationName); } @Override - public MinAggregator.MinAggregatorBuilder getFactoryPrototypes() { - return MinAggregator.MinAggregatorBuilder.PROTOTYPE; + public MinAggregatorBuilder getFactoryPrototypes() { + return MinAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregator.java index 81722d3b7f0..ab4335a704e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregator.java @@ -20,9 +20,6 @@ package org.elasticsearch.search.aggregations.metrics.scripted; import org.apache.lucene.index.LeafReaderContext; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.LeafSearchScript; import org.elasticsearch.script.Script; @@ -30,12 +27,9 @@ import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.metrics.MetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; @@ -43,7 +37,6 @@ import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; public class ScriptedMetricAggregator extends MetricsAggregator { @@ -106,186 +99,4 @@ public class ScriptedMetricAggregator extends MetricsAggregator { return new InternalScriptedMetric(name, null, reduceScript, pipelineAggregators(), metaData()); } - public static class ScriptedMetricAggregatorBuilder extends AggregatorBuilder { - - static final ScriptedMetricAggregatorBuilder PROTOTYPE = new ScriptedMetricAggregatorBuilder(""); - - private Script initScript; - private Script mapScript; - private Script combineScript; - private Script reduceScript; - private Map params; - - public ScriptedMetricAggregatorBuilder(String name) { - super(name, InternalScriptedMetric.TYPE); - } - - /** - * Set the init script. - */ - public ScriptedMetricAggregatorBuilder initScript(Script initScript) { - if (initScript == null) { - throw new IllegalArgumentException("[initScript] must not be null: [" + name + "]"); - } - this.initScript = initScript; - return this; - } - - /** - * Get the init script. - */ - public Script initScript() { - return initScript; - } - - /** - * Set the map script. - */ - public ScriptedMetricAggregatorBuilder mapScript(Script mapScript) { - if (mapScript == null) { - throw new IllegalArgumentException("[mapScript] must not be null: [" + name + "]"); - } - this.mapScript = mapScript; - return this; - } - - /** - * Get the map script. - */ - public Script mapScript() { - return mapScript; - } - - /** - * Set the combine script. - */ - public ScriptedMetricAggregatorBuilder combineScript(Script combineScript) { - if (combineScript == null) { - throw new IllegalArgumentException("[combineScript] must not be null: [" + name + "]"); - } - this.combineScript = combineScript; - return this; - } - - /** - * Get the combine script. - */ - public Script combineScript() { - return combineScript; - } - - /** - * Set the reduce script. - */ - public ScriptedMetricAggregatorBuilder reduceScript(Script reduceScript) { - if (reduceScript == null) { - throw new IllegalArgumentException("[reduceScript] must not be null: [" + name + "]"); - } - this.reduceScript = reduceScript; - return this; - } - - /** - * Get the reduce script. - */ - public Script reduceScript() { - return reduceScript; - } - - /** - * Set parameters that will be available in the init, - * map and combine phases. - */ - public ScriptedMetricAggregatorBuilder params(Map params) { - if (params == null) { - throw new IllegalArgumentException("[params] must not be null: [" + name + "]"); - } - this.params = params; - return this; - } - - /** - * Get parameters that will be available in the init, - * map and combine phases. - */ - public Map params() { - return params; - } - - @Override - protected ScriptedMetricAggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, - Builder subfactoriesBuilder) throws IOException { - return new ScriptedMetricAggregatorFactory(name, type, initScript, mapScript, combineScript, reduceScript, params, context, - parent, subfactoriesBuilder, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params builderParams) throws IOException { - builder.startObject(); - if (initScript != null) { - builder.field(ScriptedMetricParser.INIT_SCRIPT_FIELD.getPreferredName(), initScript); - } - - if (mapScript != null) { - builder.field(ScriptedMetricParser.MAP_SCRIPT_FIELD.getPreferredName(), mapScript); - } - - if (combineScript != null) { - builder.field(ScriptedMetricParser.COMBINE_SCRIPT_FIELD.getPreferredName(), combineScript); - } - - if (reduceScript != null) { - builder.field(ScriptedMetricParser.REDUCE_SCRIPT_FIELD.getPreferredName(), reduceScript); - } - if (params != null) { - builder.field(ScriptedMetricParser.PARAMS_FIELD.getPreferredName()); - builder.map(params); - } - builder.endObject(); - return builder; - } - - @Override - protected ScriptedMetricAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { - ScriptedMetricAggregatorBuilder factory = new ScriptedMetricAggregatorBuilder(name); - factory.initScript = in.readOptionalStreamable(Script.SUPPLIER); - factory.mapScript = in.readOptionalStreamable(Script.SUPPLIER); - factory.combineScript = in.readOptionalStreamable(Script.SUPPLIER); - factory.reduceScript = in.readOptionalStreamable(Script.SUPPLIER); - if (in.readBoolean()) { - factory.params = in.readMap(); - } - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeOptionalStreamable(initScript); - out.writeOptionalStreamable(mapScript); - out.writeOptionalStreamable(combineScript); - out.writeOptionalStreamable(reduceScript); - boolean hasParams = params != null; - out.writeBoolean(hasParams); - if (hasParams) { - out.writeMap(params); - } - } - - @Override - protected int doHashCode() { - return Objects.hash(initScript, mapScript, combineScript, reduceScript, params); - } - - @Override - protected boolean doEquals(Object obj) { - ScriptedMetricAggregatorBuilder other = (ScriptedMetricAggregatorBuilder) obj; - return Objects.equals(initScript, other.initScript) - && Objects.equals(mapScript, other.mapScript) - && Objects.equals(combineScript, other.combineScript) - && Objects.equals(reduceScript, other.reduceScript) - && Objects.equals(params, other.params); - } - - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java new file mode 100644 index 00000000000..219c199bfda --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java @@ -0,0 +1,215 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.scripted; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.AggregatorBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; + +import java.io.IOException; +import java.util.Map; +import java.util.Objects; + +public class ScriptedMetricAggregatorBuilder extends AggregatorBuilder { + + static final ScriptedMetricAggregatorBuilder PROTOTYPE = new ScriptedMetricAggregatorBuilder(""); + + private Script initScript; + private Script mapScript; + private Script combineScript; + private Script reduceScript; + private Map params; + + public ScriptedMetricAggregatorBuilder(String name) { + super(name, InternalScriptedMetric.TYPE); + } + + /** + * Set the init script. + */ + public ScriptedMetricAggregatorBuilder initScript(Script initScript) { + if (initScript == null) { + throw new IllegalArgumentException("[initScript] must not be null: [" + name + "]"); + } + this.initScript = initScript; + return this; + } + + /** + * Get the init script. + */ + public Script initScript() { + return initScript; + } + + /** + * Set the map script. + */ + public ScriptedMetricAggregatorBuilder mapScript(Script mapScript) { + if (mapScript == null) { + throw new IllegalArgumentException("[mapScript] must not be null: [" + name + "]"); + } + this.mapScript = mapScript; + return this; + } + + /** + * Get the map script. + */ + public Script mapScript() { + return mapScript; + } + + /** + * Set the combine script. + */ + public ScriptedMetricAggregatorBuilder combineScript(Script combineScript) { + if (combineScript == null) { + throw new IllegalArgumentException("[combineScript] must not be null: [" + name + "]"); + } + this.combineScript = combineScript; + return this; + } + + /** + * Get the combine script. + */ + public Script combineScript() { + return combineScript; + } + + /** + * Set the reduce script. + */ + public ScriptedMetricAggregatorBuilder reduceScript(Script reduceScript) { + if (reduceScript == null) { + throw new IllegalArgumentException("[reduceScript] must not be null: [" + name + "]"); + } + this.reduceScript = reduceScript; + return this; + } + + /** + * Get the reduce script. + */ + public Script reduceScript() { + return reduceScript; + } + + /** + * Set parameters that will be available in the init, + * map and combine phases. + */ + public ScriptedMetricAggregatorBuilder params(Map params) { + if (params == null) { + throw new IllegalArgumentException("[params] must not be null: [" + name + "]"); + } + this.params = params; + return this; + } + + /** + * Get parameters that will be available in the init, + * map and combine phases. + */ + public Map params() { + return params; + } + + @Override + protected ScriptedMetricAggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, + Builder subfactoriesBuilder) throws IOException { + return new ScriptedMetricAggregatorFactory(name, type, initScript, mapScript, combineScript, reduceScript, params, context, + parent, subfactoriesBuilder, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params builderParams) throws IOException { + builder.startObject(); + if (initScript != null) { + builder.field(ScriptedMetricParser.INIT_SCRIPT_FIELD.getPreferredName(), initScript); + } + + if (mapScript != null) { + builder.field(ScriptedMetricParser.MAP_SCRIPT_FIELD.getPreferredName(), mapScript); + } + + if (combineScript != null) { + builder.field(ScriptedMetricParser.COMBINE_SCRIPT_FIELD.getPreferredName(), combineScript); + } + + if (reduceScript != null) { + builder.field(ScriptedMetricParser.REDUCE_SCRIPT_FIELD.getPreferredName(), reduceScript); + } + if (params != null) { + builder.field(ScriptedMetricParser.PARAMS_FIELD.getPreferredName()); + builder.map(params); + } + builder.endObject(); + return builder; + } + + @Override + protected ScriptedMetricAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { + ScriptedMetricAggregatorBuilder factory = new ScriptedMetricAggregatorBuilder(name); + factory.initScript = in.readOptionalStreamable(Script.SUPPLIER); + factory.mapScript = in.readOptionalStreamable(Script.SUPPLIER); + factory.combineScript = in.readOptionalStreamable(Script.SUPPLIER); + factory.reduceScript = in.readOptionalStreamable(Script.SUPPLIER); + if (in.readBoolean()) { + factory.params = in.readMap(); + } + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeOptionalStreamable(initScript); + out.writeOptionalStreamable(mapScript); + out.writeOptionalStreamable(combineScript); + out.writeOptionalStreamable(reduceScript); + boolean hasParams = params != null; + out.writeBoolean(hasParams); + if (hasParams) { + out.writeMap(params); + } + } + + @Override + protected int doHashCode() { + return Objects.hash(initScript, mapScript, combineScript, reduceScript, params); + } + + @Override + protected boolean doEquals(Object obj) { + ScriptedMetricAggregatorBuilder other = (ScriptedMetricAggregatorBuilder) obj; + return Objects.equals(initScript, other.initScript) + && Objects.equals(mapScript, other.mapScript) + && Objects.equals(combineScript, other.combineScript) + && Objects.equals(reduceScript, other.reduceScript) + && Objects.equals(params, other.params); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricParser.java index 7e4ae0e883f..65035692e15 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricParser.java @@ -52,7 +52,7 @@ public class ScriptedMetricParser implements Aggregator.Parser { } @Override - public ScriptedMetricAggregator.ScriptedMetricAggregatorBuilder parse(String aggregationName, XContentParser parser, + public ScriptedMetricAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException { Script initScript = null; Script mapScript = null; @@ -140,7 +140,7 @@ public class ScriptedMetricParser implements Aggregator.Parser { throw new ParsingException(parser.getTokenLocation(), "map_script field is required in [" + aggregationName + "]."); } - ScriptedMetricAggregator.ScriptedMetricAggregatorBuilder factory = new ScriptedMetricAggregator.ScriptedMetricAggregatorBuilder(aggregationName); + ScriptedMetricAggregatorBuilder factory = new ScriptedMetricAggregatorBuilder(aggregationName); if (initScript != null) { factory.initScript(initScript); } @@ -160,8 +160,8 @@ public class ScriptedMetricParser implements Aggregator.Parser { } @Override - public ScriptedMetricAggregator.ScriptedMetricAggregatorBuilder getFactoryPrototypes() { - return ScriptedMetricAggregator.ScriptedMetricAggregatorBuilder.PROTOTYPE; + public ScriptedMetricAggregatorBuilder getFactoryPrototypes() { + return ScriptedMetricAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregator.java index 26e9f823751..e94edc0f140 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregator.java @@ -19,29 +19,19 @@ package org.elasticsearch.search.aggregations.metrics.stats; import org.apache.lucene.index.LeafReaderContext; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.LongArray; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; @@ -163,47 +153,6 @@ public class StatsAggregator extends NumericMetricsAggregator.MultiValue { return new InternalStats(name, 0, 0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, formatter, pipelineAggregators(), metaData()); } - public static class StatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final StatsAggregatorBuilder PROTOTYPE = new StatsAggregatorBuilder(""); - - public StatsAggregatorBuilder(String name) { - super(name, InternalStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); - } - - @Override - protected StatsAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new StatsAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected StatsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new StatsAggregator.StatsAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(Object obj) { - return true; - } - } - @Override public void doClose() { Releasables.close(counts, maxes, mins, sums); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java new file mode 100644 index 00000000000..646332f97ad --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java @@ -0,0 +1,77 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.stats; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.ToXContent.Params; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; + +import java.io.IOException; + +public class StatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { + + static final StatsAggregatorBuilder PROTOTYPE = new StatsAggregatorBuilder(""); + + public StatsAggregatorBuilder(String name) { + super(name, InternalStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected StatsAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new StatsAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected StatsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) { + return new StatsAggregatorBuilder(name); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(Object obj) { + return true; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java index 3bf8bc9715f..6bf558d197d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java @@ -50,13 +50,13 @@ public class StatsParser extends NumericValuesSourceParser { } @Override - protected StatsAggregator.StatsAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected StatsAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - return new StatsAggregator.StatsAggregatorBuilder(aggregationName); + return new StatsAggregatorBuilder(aggregationName); } @Override public AggregatorBuilder getFactoryPrototypes() { - return StatsAggregator.StatsAggregatorBuilder.PROTOTYPE; + return StatsAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java index 1449b71a2c4..4687002cf12 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java @@ -20,35 +20,24 @@ package org.elasticsearch.search.aggregations.metrics.stats.extended; import org.apache.lucene.index.LeafReaderContext; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.DoubleArray; import org.elasticsearch.common.util.LongArray; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Objects; /** * @@ -199,63 +188,4 @@ public class ExtendedStatsAggregator extends NumericMetricsAggregator.MultiValue public void doClose() { Releasables.close(counts, maxes, mins, sumOfSqrs, sums); } - - public static class ExtendedStatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final ExtendedStatsAggregatorBuilder PROTOTYPE = new ExtendedStatsAggregatorBuilder(""); - - private double sigma = 2.0; - - public ExtendedStatsAggregatorBuilder(String name) { - super(name, InternalExtendedStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); - } - - public ExtendedStatsAggregatorBuilder sigma(double sigma) { - if (sigma < 0.0) { - throw new IllegalArgumentException("[sigma] must be greater than or equal to 0. Found [" + sigma + "] in [" + name + "]"); - } - this.sigma = sigma; - return this; - } - - public double sigma() { - return sigma; - } - - @Override - protected ExtendedStatsAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new ExtendedStatsAggregatorFactory(name, type, config, sigma, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected ExtendedStatsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder factory = new ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder(name); - factory.sigma = in.readDouble(); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeDouble(sigma); - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.field(SIGMA_FIELD.getPreferredName(), sigma); - return builder; - } - - @Override - protected int innerHashCode() { - return Objects.hash(sigma); - } - - @Override - protected boolean innerEquals(Object obj) { - ExtendedStatsAggregatorBuilder other = (ExtendedStatsAggregatorBuilder) obj; - return Objects.equals(sigma, other.sigma); - } - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java new file mode 100644 index 00000000000..80fd04b6c18 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.stats.extended; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; + +import java.io.IOException; +import java.util.Objects; + +public class ExtendedStatsAggregatorBuilder + extends ValuesSourceAggregatorBuilder.LeafOnly { + + static final ExtendedStatsAggregatorBuilder PROTOTYPE = new ExtendedStatsAggregatorBuilder(""); + + private double sigma = 2.0; + + public ExtendedStatsAggregatorBuilder(String name) { + super(name, InternalExtendedStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + public ExtendedStatsAggregatorBuilder sigma(double sigma) { + if (sigma < 0.0) { + throw new IllegalArgumentException("[sigma] must be greater than or equal to 0. Found [" + sigma + "] in [" + name + "]"); + } + this.sigma = sigma; + return this; + } + + public double sigma() { + return sigma; + } + + @Override + protected ExtendedStatsAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new ExtendedStatsAggregatorFactory(name, type, config, sigma, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected ExtendedStatsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) throws IOException { + ExtendedStatsAggregatorBuilder factory = new ExtendedStatsAggregatorBuilder(name); + factory.sigma = in.readDouble(); + return factory; + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeDouble(sigma); + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + builder.field(ExtendedStatsAggregator.SIGMA_FIELD.getPreferredName(), sigma); + return builder; + } + + @Override + protected int innerHashCode() { + return Objects.hash(sigma); + } + + @Override + protected boolean innerEquals(Object obj) { + ExtendedStatsAggregatorBuilder other = (ExtendedStatsAggregatorBuilder) obj; + return Objects.equals(sigma, other.sigma); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java index a934a49adf7..faae604111a 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java @@ -56,9 +56,9 @@ public class ExtendedStatsParser extends NumericValuesSourceParser { } @Override - protected ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected ExtendedStatsAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder factory = new ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder(aggregationName); + ExtendedStatsAggregatorBuilder factory = new ExtendedStatsAggregatorBuilder(aggregationName); Double sigma = (Double) otherOptions.get(ExtendedStatsAggregator.SIGMA_FIELD); if (sigma != null) { factory.sigma(sigma); @@ -68,6 +68,6 @@ public class ExtendedStatsParser extends NumericValuesSourceParser { @Override public AggregatorBuilder getFactoryPrototypes() { - return ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder.PROTOTYPE; + return ExtendedStatsAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java index ba46ffaf5c4..29dcaf47dda 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java @@ -19,28 +19,18 @@ package org.elasticsearch.search.aggregations.metrics.sum; import org.apache.lucene.index.LeafReaderContext; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.DoubleArray; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; @@ -113,47 +103,6 @@ public class SumAggregator extends NumericMetricsAggregator.SingleValue { return new InternalSum(name, 0.0, formatter, pipelineAggregators(), metaData()); } - public static class SumAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final SumAggregatorBuilder PROTOTYPE = new SumAggregatorBuilder(""); - - public SumAggregatorBuilder(String name) { - super(name, InternalSum.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); - } - - @Override - protected SumAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - return new SumAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected ValuesSourceAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new SumAggregator.SumAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(Object obj) { - return true; - } - } - @Override public void doClose() { Releasables.close(sums); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java new file mode 100644 index 00000000000..17671d9ffa3 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java @@ -0,0 +1,76 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.sum; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; + +import java.io.IOException; + +public class SumAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { + + static final SumAggregatorBuilder PROTOTYPE = new SumAggregatorBuilder(""); + + public SumAggregatorBuilder(String name) { + super(name, InternalSum.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected SumAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { + return new SumAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected ValuesSourceAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, + ValueType targetValueType, StreamInput in) { + return new SumAggregatorBuilder(name); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(Object obj) { + return true; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java index 7712f8807bd..92664c9a6d8 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java @@ -50,13 +50,13 @@ public class SumParser extends NumericValuesSourceParser { } @Override - protected SumAggregator.SumAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, + protected SumAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - return new SumAggregator.SumAggregatorBuilder(aggregationName); + return new SumAggregatorBuilder(aggregationName); } @Override public AggregatorBuilder getFactoryPrototypes() { - return SumAggregator.SumAggregatorBuilder.PROTOTYPE; + return SumAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java index b78caa14668..8e50dc60ea8 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java @@ -30,48 +30,25 @@ import org.apache.lucene.search.TopDocsCollector; import org.apache.lucene.search.TopFieldCollector; import org.apache.lucene.search.TopFieldDocs; import org.apache.lucene.search.TopScoreDocCollector; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.util.LongObjectPagedHashMap; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.script.Script; -import org.elasticsearch.search.aggregations.AggregationInitializationException; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactory; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.metrics.MetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.search.builder.SearchSourceBuilder.ScriptField; import org.elasticsearch.search.fetch.FetchPhase; import org.elasticsearch.search.fetch.FetchSearchResult; -import org.elasticsearch.search.fetch.source.FetchSourceContext; -import org.elasticsearch.search.highlight.HighlightBuilder; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.InternalSearchHits; import org.elasticsearch.search.internal.SubSearchContext; -import org.elasticsearch.search.sort.SortBuilder; -import org.elasticsearch.search.sort.SortBuilders; -import org.elasticsearch.search.sort.SortOrder; + import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; /** */ @@ -200,599 +177,4 @@ public class TopHitsAggregator extends MetricsAggregator { protected void doClose() { Releasables.close(topDocsCollectors); } - - public static class TopHitsAggregatorBuilder extends AggregatorBuilder { - - static final TopHitsAggregatorBuilder PROTOTYPE = new TopHitsAggregatorBuilder(""); - - private int from = 0; - private int size = 3; - private boolean explain = false; - private boolean version = false; - private boolean trackScores = false; - private List sorts = null; - private HighlightBuilder highlightBuilder; - private List fieldNames; - private List fieldDataFields; - private List scriptFields; - private FetchSourceContext fetchSourceContext; - - public TopHitsAggregatorBuilder(String name) { - super(name, InternalTopHits.TYPE); - } - - /** - * From index to start the search from. Defaults to 0. - */ - public TopHitsAggregatorBuilder from(int from) { - if (from < 0) { - throw new IllegalArgumentException("[from] must be greater than or equal to 0. Found [" + from + "] in [" + name + "]"); - } - this.from = from; - return this; - } - - /** - * Gets the from index to start the search from. - **/ - public int from() { - return from; - } - - /** - * The number of search hits to return. Defaults to 10. - */ - public TopHitsAggregatorBuilder size(int size) { - if (size < 0) { - throw new IllegalArgumentException("[size] must be greater than or equal to 0. Found [" + size + "] in [" + name + "]"); - } - this.size = size; - return this; - } - - /** - * Gets the number of search hits to return. - */ - public int size() { - return size; - } - - /** - * Adds a sort against the given field name and the sort ordering. - * - * @param name - * The name of the field - * @param order - * The sort ordering - */ - public TopHitsAggregatorBuilder sort(String name, SortOrder order) { - if (name == null) { - throw new IllegalArgumentException("sort [name] must not be null: [" + name + "]"); - } - if (order == null) { - throw new IllegalArgumentException("sort [order] must not be null: [" + name + "]"); - } - sort(SortBuilders.fieldSort(name).order(order)); - return this; - } - - /** - * Add a sort against the given field name. - * - * @param name - * The name of the field to sort by - */ - public TopHitsAggregatorBuilder sort(String name) { - if (name == null) { - throw new IllegalArgumentException("sort [name] must not be null: [" + name + "]"); - } - sort(SortBuilders.fieldSort(name)); - return this; - } - - /** - * Adds a sort builder. - */ - public TopHitsAggregatorBuilder sort(SortBuilder sort) { - if (sort == null) { - throw new IllegalArgumentException("[sort] must not be null: [" + name + "]"); - } - try { - if (sorts == null) { - sorts = new ArrayList<>(); - } - // NORELEASE when sort has been refactored and made writeable - // add the sortBuilcer to the List directly instead of - // serialising to XContent - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - sort.toXContent(builder, EMPTY_PARAMS); - builder.endObject(); - sorts.add(builder.bytes()); - } catch (IOException e) { - throw new RuntimeException(e); - } - return this; - } - - /** - * Adds a sort builder. - */ - public TopHitsAggregatorBuilder sorts(List sorts) { - if (sorts == null) { - throw new IllegalArgumentException("[sorts] must not be null: [" + name + "]"); - } - if (this.sorts == null) { - this.sorts = new ArrayList<>(); - } - for (BytesReference sort : sorts) { - this.sorts.add(sort); - } - return this; - } - - /** - * Gets the bytes representing the sort builders for this request. - */ - public List sorts() { - return sorts; - } - - /** - * Adds highlight to perform as part of the search. - */ - public TopHitsAggregatorBuilder highlighter(HighlightBuilder highlightBuilder) { - if (highlightBuilder == null) { - throw new IllegalArgumentException("[highlightBuilder] must not be null: [" + name + "]"); - } - this.highlightBuilder = highlightBuilder; - return this; - } - - /** - * Gets the hightlighter builder for this request. - */ - public HighlightBuilder highlighter() { - return highlightBuilder; - } - - /** - * Indicates whether the response should contain the stored _source for - * every hit - */ - public TopHitsAggregatorBuilder fetchSource(boolean fetch) { - if (this.fetchSourceContext == null) { - this.fetchSourceContext = new FetchSourceContext(fetch); - } else { - this.fetchSourceContext.fetchSource(fetch); - } - return this; - } - - /** - * Indicate that _source should be returned with every hit, with an - * "include" and/or "exclude" set which can include simple wildcard - * elements. - * - * @param include - * An optional include (optionally wildcarded) pattern to - * filter the returned _source - * @param exclude - * An optional exclude (optionally wildcarded) pattern to - * filter the returned _source - */ - public TopHitsAggregatorBuilder fetchSource(@Nullable String include, @Nullable String exclude) { - fetchSource(include == null ? Strings.EMPTY_ARRAY : new String[] { include }, - exclude == null ? Strings.EMPTY_ARRAY : new String[] { exclude }); - return this; - } - - /** - * Indicate that _source should be returned with every hit, with an - * "include" and/or "exclude" set which can include simple wildcard - * elements. - * - * @param includes - * An optional list of include (optionally wildcarded) - * pattern to filter the returned _source - * @param excludes - * An optional list of exclude (optionally wildcarded) - * pattern to filter the returned _source - */ - public TopHitsAggregatorBuilder fetchSource(@Nullable String[] includes, @Nullable String[] excludes) { - fetchSourceContext = new FetchSourceContext(includes, excludes); - return this; - } - - /** - * Indicate how the _source should be fetched. - */ - public TopHitsAggregatorBuilder fetchSource(@Nullable FetchSourceContext fetchSourceContext) { - if (fetchSourceContext == null) { - throw new IllegalArgumentException("[fetchSourceContext] must not be null: [" + name + "]"); - } - this.fetchSourceContext = fetchSourceContext; - return this; - } - - /** - * Gets the {@link FetchSourceContext} which defines how the _source - * should be fetched. - */ - public FetchSourceContext fetchSource() { - return fetchSourceContext; - } - - /** - * Adds a field to load and return (note, it must be stored) as part of - * the search request. If none are specified, the source of the document - * will be return. - */ - public TopHitsAggregatorBuilder field(String field) { - if (field == null) { - throw new IllegalArgumentException("[field] must not be null: [" + name + "]"); - } - if (fieldNames == null) { - fieldNames = new ArrayList<>(); - } - fieldNames.add(field); - return this; - } - - /** - * Sets the fields to load and return as part of the search request. If - * none are specified, the source of the document will be returned. - */ - public TopHitsAggregatorBuilder fields(List fields) { - if (fields == null) { - throw new IllegalArgumentException("[fields] must not be null: [" + name + "]"); - } - this.fieldNames = fields; - return this; - } - - /** - * Sets no fields to be loaded, resulting in only id and type to be - * returned per field. - */ - public TopHitsAggregatorBuilder noFields() { - this.fieldNames = Collections.emptyList(); - return this; - } - - /** - * Gets the fields to load and return as part of the search request. - */ - public List fields() { - return fieldNames; - } - - /** - * Adds a field to load from the field data cache and return as part of - * the search request. - */ - public TopHitsAggregatorBuilder fieldDataField(String fieldDataField) { - if (fieldDataField == null) { - throw new IllegalArgumentException("[fieldDataField] must not be null: [" + name + "]"); - } - if (fieldDataFields == null) { - fieldDataFields = new ArrayList<>(); - } - fieldDataFields.add(fieldDataField); - return this; - } - - /** - * Adds fields to load from the field data cache and return as part of - * the search request. - */ - public TopHitsAggregatorBuilder fieldDataFields(List fieldDataFields) { - if (fieldDataFields == null) { - throw new IllegalArgumentException("[fieldDataFields] must not be null: [" + name + "]"); - } - if (this.fieldDataFields == null) { - this.fieldDataFields = new ArrayList<>(); - } - this.fieldDataFields.addAll(fieldDataFields); - return this; - } - - /** - * Gets the field-data fields. - */ - public List fieldDataFields() { - return fieldDataFields; - } - - /** - * Adds a script field under the given name with the provided script. - * - * @param name - * The name of the field - * @param script - * The script - */ - public TopHitsAggregatorBuilder scriptField(String name, Script script) { - if (name == null) { - throw new IllegalArgumentException("scriptField [name] must not be null: [" + name + "]"); - } - if (script == null) { - throw new IllegalArgumentException("scriptField [script] must not be null: [" + name + "]"); - } - scriptField(name, script, false); - return this; - } - - /** - * Adds a script field under the given name with the provided script. - * - * @param name - * The name of the field - * @param script - * The script - */ - public TopHitsAggregatorBuilder scriptField(String name, Script script, boolean ignoreFailure) { - if (name == null) { - throw new IllegalArgumentException("scriptField [name] must not be null: [" + name + "]"); - } - if (script == null) { - throw new IllegalArgumentException("scriptField [script] must not be null: [" + name + "]"); - } - if (scriptFields == null) { - scriptFields = new ArrayList<>(); - } - scriptFields.add(new ScriptField(name, script, ignoreFailure)); - return this; - } - - public TopHitsAggregatorBuilder scriptFields(List scriptFields) { - if (scriptFields == null) { - throw new IllegalArgumentException("[scriptFields] must not be null: [" + name + "]"); - } - if (this.scriptFields == null) { - this.scriptFields = new ArrayList<>(); - } - this.scriptFields.addAll(scriptFields); - return this; - } - - /** - * Gets the script fields. - */ - public List scriptFields() { - return scriptFields; - } - - /** - * Should each {@link org.elasticsearch.search.SearchHit} be returned - * with an explanation of the hit (ranking). - */ - public TopHitsAggregatorBuilder explain(boolean explain) { - this.explain = explain; - return this; - } - - /** - * Indicates whether each search hit will be returned with an - * explanation of the hit (ranking) - */ - public boolean explain() { - return explain; - } - - /** - * Should each {@link org.elasticsearch.search.SearchHit} be returned - * with a version associated with it. - */ - public TopHitsAggregatorBuilder version(boolean version) { - this.version = version; - return this; - } - - /** - * Indicates whether the document's version will be included in the - * search hits. - */ - public boolean version() { - return version; - } - - /** - * Applies when sorting, and controls if scores will be tracked as well. - * Defaults to false. - */ - public TopHitsAggregatorBuilder trackScores(boolean trackScores) { - this.trackScores = trackScores; - return this; - } - - /** - * Indicates whether scores will be tracked for this request. - */ - public boolean trackScores() { - return trackScores; - } - - @Override - public TopHitsAggregatorBuilder subAggregations(Builder subFactories) { - throw new AggregationInitializationException("Aggregator [" + name + "] of type [" + type + "] cannot accept sub-aggregations"); - } - - @Override - protected TopHitsAggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subfactoriesBuilder) - throws IOException { - return new TopHitsAggregatorFactory(name, type, from, size, explain, version, trackScores, sorts, highlightBuilder, fieldNames, - fieldDataFields, scriptFields, fetchSourceContext, context, parent, subfactoriesBuilder, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.field(SearchSourceBuilder.FROM_FIELD.getPreferredName(), from); - builder.field(SearchSourceBuilder.SIZE_FIELD.getPreferredName(), size); - builder.field(SearchSourceBuilder.VERSION_FIELD.getPreferredName(), version); - builder.field(SearchSourceBuilder.EXPLAIN_FIELD.getPreferredName(), explain); - if (fetchSourceContext != null) { - builder.field(SearchSourceBuilder._SOURCE_FIELD.getPreferredName(), fetchSourceContext); - } - if (fieldNames != null) { - if (fieldNames.size() == 1) { - builder.field(SearchSourceBuilder.FIELDS_FIELD.getPreferredName(), fieldNames.get(0)); - } else { - builder.startArray(SearchSourceBuilder.FIELDS_FIELD.getPreferredName()); - for (String fieldName : fieldNames) { - builder.value(fieldName); - } - builder.endArray(); - } - } - if (fieldDataFields != null) { - builder.startArray(SearchSourceBuilder.FIELDDATA_FIELDS_FIELD.getPreferredName()); - for (String fieldDataField : fieldDataFields) { - builder.value(fieldDataField); - } - builder.endArray(); - } - if (scriptFields != null) { - builder.startObject(SearchSourceBuilder.SCRIPT_FIELDS_FIELD.getPreferredName()); - for (ScriptField scriptField : scriptFields) { - scriptField.toXContent(builder, params); - } - builder.endObject(); - } - if (sorts != null) { - builder.startArray(SearchSourceBuilder.SORT_FIELD.getPreferredName()); - for (BytesReference sort : sorts) { - XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(sort); - parser.nextToken(); - builder.copyCurrentStructure(parser); - } - builder.endArray(); - } - if (trackScores) { - builder.field(SearchSourceBuilder.TRACK_SCORES_FIELD.getPreferredName(), true); - } - if (highlightBuilder != null) { - this.highlightBuilder.toXContent(builder, params); - } - builder.endObject(); - return builder; - } - - @Override - protected TopHitsAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { - TopHitsAggregatorBuilder factory = new TopHitsAggregatorBuilder(name); - factory.explain = in.readBoolean(); - factory.fetchSourceContext = FetchSourceContext.optionalReadFromStream(in); - if (in.readBoolean()) { - int size = in.readVInt(); - List fieldDataFields = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - fieldDataFields.add(in.readString()); - } - factory.fieldDataFields = fieldDataFields; - } - if (in.readBoolean()) { - int size = in.readVInt(); - List fieldNames = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - fieldNames.add(in.readString()); - } - factory.fieldNames = fieldNames; - } - factory.from = in.readVInt(); - if (in.readBoolean()) { - factory.highlightBuilder = HighlightBuilder.PROTOTYPE.readFrom(in); - } - if (in.readBoolean()) { - int size = in.readVInt(); - List scriptFields = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - scriptFields.add(ScriptField.PROTOTYPE.readFrom(in)); - } - factory.scriptFields = scriptFields; - } - factory.size = in.readVInt(); - if (in.readBoolean()) { - int size = in.readVInt(); - List sorts = new ArrayList<>(); - for (int i = 0; i < size; i++) { - sorts.add(in.readBytesReference()); - } - factory.sorts = sorts; - } - factory.trackScores = in.readBoolean(); - factory.version = in.readBoolean(); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeBoolean(explain); - FetchSourceContext.optionalWriteToStream(fetchSourceContext, out); - boolean hasFieldDataFields = fieldDataFields != null; - out.writeBoolean(hasFieldDataFields); - if (hasFieldDataFields) { - out.writeVInt(fieldDataFields.size()); - for (String fieldName : fieldDataFields) { - out.writeString(fieldName); - } - } - boolean hasFieldNames = fieldNames != null; - out.writeBoolean(hasFieldNames); - if (hasFieldNames) { - out.writeVInt(fieldNames.size()); - for (String fieldName : fieldNames) { - out.writeString(fieldName); - } - } - out.writeVInt(from); - boolean hasHighlighter = highlightBuilder != null; - out.writeBoolean(hasHighlighter); - if (hasHighlighter) { - highlightBuilder.writeTo(out); - } - boolean hasScriptFields = scriptFields != null; - out.writeBoolean(hasScriptFields); - if (hasScriptFields) { - out.writeVInt(scriptFields.size()); - for (ScriptField scriptField : scriptFields) { - scriptField.writeTo(out); - } - } - out.writeVInt(size); - boolean hasSorts = sorts != null; - out.writeBoolean(hasSorts); - if (hasSorts) { - out.writeVInt(sorts.size()); - for (BytesReference sort : sorts) { - out.writeBytesReference(sort); - } - } - out.writeBoolean(trackScores); - out.writeBoolean(version); - } - - @Override - protected int doHashCode() { - return Objects.hash(explain, fetchSourceContext, fieldDataFields, fieldNames, from, highlightBuilder, scriptFields, size, sorts, - trackScores, version); - } - - @Override - protected boolean doEquals(Object obj) { - TopHitsAggregatorBuilder other = (TopHitsAggregatorBuilder) obj; - return Objects.equals(explain, other.explain) - && Objects.equals(fetchSourceContext, other.fetchSourceContext) - && Objects.equals(fieldDataFields, other.fieldDataFields) - && Objects.equals(fieldNames, other.fieldNames) - && Objects.equals(from, other.from) - && Objects.equals(highlightBuilder, other.highlightBuilder) - && Objects.equals(scriptFields, other.scriptFields) - && Objects.equals(size, other.size) - && Objects.equals(sorts, other.sorts) - && Objects.equals(trackScores, other.trackScores) - && Objects.equals(version, other.version); - } - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java new file mode 100644 index 00000000000..a15a61eaae2 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java @@ -0,0 +1,644 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.tophits; + +import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.AggregationInitializationException; +import org.elasticsearch.search.aggregations.AggregatorBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.builder.SearchSourceBuilder.ScriptField; +import org.elasticsearch.search.fetch.source.FetchSourceContext; +import org.elasticsearch.search.highlight.HighlightBuilder; +import org.elasticsearch.search.sort.SortBuilder; +import org.elasticsearch.search.sort.SortBuilders; +import org.elasticsearch.search.sort.SortOrder; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +public class TopHitsAggregatorBuilder extends AggregatorBuilder { + + static final TopHitsAggregatorBuilder PROTOTYPE = new TopHitsAggregatorBuilder(""); + + private int from = 0; + private int size = 3; + private boolean explain = false; + private boolean version = false; + private boolean trackScores = false; + private List sorts = null; + private HighlightBuilder highlightBuilder; + private List fieldNames; + private List fieldDataFields; + private List scriptFields; + private FetchSourceContext fetchSourceContext; + + public TopHitsAggregatorBuilder(String name) { + super(name, InternalTopHits.TYPE); + } + + /** + * From index to start the search from. Defaults to 0. + */ + public TopHitsAggregatorBuilder from(int from) { + if (from < 0) { + throw new IllegalArgumentException("[from] must be greater than or equal to 0. Found [" + from + "] in [" + name + "]"); + } + this.from = from; + return this; + } + + /** + * Gets the from index to start the search from. + **/ + public int from() { + return from; + } + + /** + * The number of search hits to return. Defaults to 10. + */ + public TopHitsAggregatorBuilder size(int size) { + if (size < 0) { + throw new IllegalArgumentException("[size] must be greater than or equal to 0. Found [" + size + "] in [" + name + "]"); + } + this.size = size; + return this; + } + + /** + * Gets the number of search hits to return. + */ + public int size() { + return size; + } + + /** + * Adds a sort against the given field name and the sort ordering. + * + * @param name + * The name of the field + * @param order + * The sort ordering + */ + public TopHitsAggregatorBuilder sort(String name, SortOrder order) { + if (name == null) { + throw new IllegalArgumentException("sort [name] must not be null: [" + name + "]"); + } + if (order == null) { + throw new IllegalArgumentException("sort [order] must not be null: [" + name + "]"); + } + sort(SortBuilders.fieldSort(name).order(order)); + return this; + } + + /** + * Add a sort against the given field name. + * + * @param name + * The name of the field to sort by + */ + public TopHitsAggregatorBuilder sort(String name) { + if (name == null) { + throw new IllegalArgumentException("sort [name] must not be null: [" + name + "]"); + } + sort(SortBuilders.fieldSort(name)); + return this; + } + + /** + * Adds a sort builder. + */ + public TopHitsAggregatorBuilder sort(SortBuilder sort) { + if (sort == null) { + throw new IllegalArgumentException("[sort] must not be null: [" + name + "]"); + } + try { + if (sorts == null) { + sorts = new ArrayList<>(); + } + // NORELEASE when sort has been refactored and made writeable + // add the sortBuilcer to the List directly instead of + // serialising to XContent + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + sort.toXContent(builder, EMPTY_PARAMS); + builder.endObject(); + sorts.add(builder.bytes()); + } catch (IOException e) { + throw new RuntimeException(e); + } + return this; + } + + /** + * Adds a sort builder. + */ + public TopHitsAggregatorBuilder sorts(List sorts) { + if (sorts == null) { + throw new IllegalArgumentException("[sorts] must not be null: [" + name + "]"); + } + if (this.sorts == null) { + this.sorts = new ArrayList<>(); + } + for (BytesReference sort : sorts) { + this.sorts.add(sort); + } + return this; + } + + /** + * Gets the bytes representing the sort builders for this request. + */ + public List sorts() { + return sorts; + } + + /** + * Adds highlight to perform as part of the search. + */ + public TopHitsAggregatorBuilder highlighter(HighlightBuilder highlightBuilder) { + if (highlightBuilder == null) { + throw new IllegalArgumentException("[highlightBuilder] must not be null: [" + name + "]"); + } + this.highlightBuilder = highlightBuilder; + return this; + } + + /** + * Gets the hightlighter builder for this request. + */ + public HighlightBuilder highlighter() { + return highlightBuilder; + } + + /** + * Indicates whether the response should contain the stored _source for + * every hit + */ + public TopHitsAggregatorBuilder fetchSource(boolean fetch) { + if (this.fetchSourceContext == null) { + this.fetchSourceContext = new FetchSourceContext(fetch); + } else { + this.fetchSourceContext.fetchSource(fetch); + } + return this; + } + + /** + * Indicate that _source should be returned with every hit, with an + * "include" and/or "exclude" set which can include simple wildcard + * elements. + * + * @param include + * An optional include (optionally wildcarded) pattern to + * filter the returned _source + * @param exclude + * An optional exclude (optionally wildcarded) pattern to + * filter the returned _source + */ + public TopHitsAggregatorBuilder fetchSource(@Nullable String include, @Nullable String exclude) { + fetchSource(include == null ? Strings.EMPTY_ARRAY : new String[] { include }, + exclude == null ? Strings.EMPTY_ARRAY : new String[] { exclude }); + return this; + } + + /** + * Indicate that _source should be returned with every hit, with an + * "include" and/or "exclude" set which can include simple wildcard + * elements. + * + * @param includes + * An optional list of include (optionally wildcarded) + * pattern to filter the returned _source + * @param excludes + * An optional list of exclude (optionally wildcarded) + * pattern to filter the returned _source + */ + public TopHitsAggregatorBuilder fetchSource(@Nullable String[] includes, @Nullable String[] excludes) { + fetchSourceContext = new FetchSourceContext(includes, excludes); + return this; + } + + /** + * Indicate how the _source should be fetched. + */ + public TopHitsAggregatorBuilder fetchSource(@Nullable FetchSourceContext fetchSourceContext) { + if (fetchSourceContext == null) { + throw new IllegalArgumentException("[fetchSourceContext] must not be null: [" + name + "]"); + } + this.fetchSourceContext = fetchSourceContext; + return this; + } + + /** + * Gets the {@link FetchSourceContext} which defines how the _source + * should be fetched. + */ + public FetchSourceContext fetchSource() { + return fetchSourceContext; + } + + /** + * Adds a field to load and return (note, it must be stored) as part of + * the search request. If none are specified, the source of the document + * will be return. + */ + public TopHitsAggregatorBuilder field(String field) { + if (field == null) { + throw new IllegalArgumentException("[field] must not be null: [" + name + "]"); + } + if (fieldNames == null) { + fieldNames = new ArrayList<>(); + } + fieldNames.add(field); + return this; + } + + /** + * Sets the fields to load and return as part of the search request. If + * none are specified, the source of the document will be returned. + */ + public TopHitsAggregatorBuilder fields(List fields) { + if (fields == null) { + throw new IllegalArgumentException("[fields] must not be null: [" + name + "]"); + } + this.fieldNames = fields; + return this; + } + + /** + * Sets no fields to be loaded, resulting in only id and type to be + * returned per field. + */ + public TopHitsAggregatorBuilder noFields() { + this.fieldNames = Collections.emptyList(); + return this; + } + + /** + * Gets the fields to load and return as part of the search request. + */ + public List fields() { + return fieldNames; + } + + /** + * Adds a field to load from the field data cache and return as part of + * the search request. + */ + public TopHitsAggregatorBuilder fieldDataField(String fieldDataField) { + if (fieldDataField == null) { + throw new IllegalArgumentException("[fieldDataField] must not be null: [" + name + "]"); + } + if (fieldDataFields == null) { + fieldDataFields = new ArrayList<>(); + } + fieldDataFields.add(fieldDataField); + return this; + } + + /** + * Adds fields to load from the field data cache and return as part of + * the search request. + */ + public TopHitsAggregatorBuilder fieldDataFields(List fieldDataFields) { + if (fieldDataFields == null) { + throw new IllegalArgumentException("[fieldDataFields] must not be null: [" + name + "]"); + } + if (this.fieldDataFields == null) { + this.fieldDataFields = new ArrayList<>(); + } + this.fieldDataFields.addAll(fieldDataFields); + return this; + } + + /** + * Gets the field-data fields. + */ + public List fieldDataFields() { + return fieldDataFields; + } + + /** + * Adds a script field under the given name with the provided script. + * + * @param name + * The name of the field + * @param script + * The script + */ + public TopHitsAggregatorBuilder scriptField(String name, Script script) { + if (name == null) { + throw new IllegalArgumentException("scriptField [name] must not be null: [" + name + "]"); + } + if (script == null) { + throw new IllegalArgumentException("scriptField [script] must not be null: [" + name + "]"); + } + scriptField(name, script, false); + return this; + } + + /** + * Adds a script field under the given name with the provided script. + * + * @param name + * The name of the field + * @param script + * The script + */ + public TopHitsAggregatorBuilder scriptField(String name, Script script, boolean ignoreFailure) { + if (name == null) { + throw new IllegalArgumentException("scriptField [name] must not be null: [" + name + "]"); + } + if (script == null) { + throw new IllegalArgumentException("scriptField [script] must not be null: [" + name + "]"); + } + if (scriptFields == null) { + scriptFields = new ArrayList<>(); + } + scriptFields.add(new ScriptField(name, script, ignoreFailure)); + return this; + } + + public TopHitsAggregatorBuilder scriptFields(List scriptFields) { + if (scriptFields == null) { + throw new IllegalArgumentException("[scriptFields] must not be null: [" + name + "]"); + } + if (this.scriptFields == null) { + this.scriptFields = new ArrayList<>(); + } + this.scriptFields.addAll(scriptFields); + return this; + } + + /** + * Gets the script fields. + */ + public List scriptFields() { + return scriptFields; + } + + /** + * Should each {@link org.elasticsearch.search.SearchHit} be returned + * with an explanation of the hit (ranking). + */ + public TopHitsAggregatorBuilder explain(boolean explain) { + this.explain = explain; + return this; + } + + /** + * Indicates whether each search hit will be returned with an + * explanation of the hit (ranking) + */ + public boolean explain() { + return explain; + } + + /** + * Should each {@link org.elasticsearch.search.SearchHit} be returned + * with a version associated with it. + */ + public TopHitsAggregatorBuilder version(boolean version) { + this.version = version; + return this; + } + + /** + * Indicates whether the document's version will be included in the + * search hits. + */ + public boolean version() { + return version; + } + + /** + * Applies when sorting, and controls if scores will be tracked as well. + * Defaults to false. + */ + public TopHitsAggregatorBuilder trackScores(boolean trackScores) { + this.trackScores = trackScores; + return this; + } + + /** + * Indicates whether scores will be tracked for this request. + */ + public boolean trackScores() { + return trackScores; + } + + @Override + public TopHitsAggregatorBuilder subAggregations(Builder subFactories) { + throw new AggregationInitializationException("Aggregator [" + name + "] of type [" + type + "] cannot accept sub-aggregations"); + } + + @Override + protected TopHitsAggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subfactoriesBuilder) + throws IOException { + return new TopHitsAggregatorFactory(name, type, from, size, explain, version, trackScores, sorts, highlightBuilder, fieldNames, + fieldDataFields, scriptFields, fetchSourceContext, context, parent, subfactoriesBuilder, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.field(SearchSourceBuilder.FROM_FIELD.getPreferredName(), from); + builder.field(SearchSourceBuilder.SIZE_FIELD.getPreferredName(), size); + builder.field(SearchSourceBuilder.VERSION_FIELD.getPreferredName(), version); + builder.field(SearchSourceBuilder.EXPLAIN_FIELD.getPreferredName(), explain); + if (fetchSourceContext != null) { + builder.field(SearchSourceBuilder._SOURCE_FIELD.getPreferredName(), fetchSourceContext); + } + if (fieldNames != null) { + if (fieldNames.size() == 1) { + builder.field(SearchSourceBuilder.FIELDS_FIELD.getPreferredName(), fieldNames.get(0)); + } else { + builder.startArray(SearchSourceBuilder.FIELDS_FIELD.getPreferredName()); + for (String fieldName : fieldNames) { + builder.value(fieldName); + } + builder.endArray(); + } + } + if (fieldDataFields != null) { + builder.startArray(SearchSourceBuilder.FIELDDATA_FIELDS_FIELD.getPreferredName()); + for (String fieldDataField : fieldDataFields) { + builder.value(fieldDataField); + } + builder.endArray(); + } + if (scriptFields != null) { + builder.startObject(SearchSourceBuilder.SCRIPT_FIELDS_FIELD.getPreferredName()); + for (ScriptField scriptField : scriptFields) { + scriptField.toXContent(builder, params); + } + builder.endObject(); + } + if (sorts != null) { + builder.startArray(SearchSourceBuilder.SORT_FIELD.getPreferredName()); + for (BytesReference sort : sorts) { + XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(sort); + parser.nextToken(); + builder.copyCurrentStructure(parser); + } + builder.endArray(); + } + if (trackScores) { + builder.field(SearchSourceBuilder.TRACK_SCORES_FIELD.getPreferredName(), true); + } + if (highlightBuilder != null) { + this.highlightBuilder.toXContent(builder, params); + } + builder.endObject(); + return builder; + } + + @Override + protected TopHitsAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException { + TopHitsAggregatorBuilder factory = new TopHitsAggregatorBuilder(name); + factory.explain = in.readBoolean(); + factory.fetchSourceContext = FetchSourceContext.optionalReadFromStream(in); + if (in.readBoolean()) { + int size = in.readVInt(); + List fieldDataFields = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + fieldDataFields.add(in.readString()); + } + factory.fieldDataFields = fieldDataFields; + } + if (in.readBoolean()) { + int size = in.readVInt(); + List fieldNames = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + fieldNames.add(in.readString()); + } + factory.fieldNames = fieldNames; + } + factory.from = in.readVInt(); + if (in.readBoolean()) { + factory.highlightBuilder = HighlightBuilder.PROTOTYPE.readFrom(in); + } + if (in.readBoolean()) { + int size = in.readVInt(); + List scriptFields = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + scriptFields.add(ScriptField.PROTOTYPE.readFrom(in)); + } + factory.scriptFields = scriptFields; + } + factory.size = in.readVInt(); + if (in.readBoolean()) { + int size = in.readVInt(); + List sorts = new ArrayList<>(); + for (int i = 0; i < size; i++) { + sorts.add(in.readBytesReference()); + } + factory.sorts = sorts; + } + factory.trackScores = in.readBoolean(); + factory.version = in.readBoolean(); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeBoolean(explain); + FetchSourceContext.optionalWriteToStream(fetchSourceContext, out); + boolean hasFieldDataFields = fieldDataFields != null; + out.writeBoolean(hasFieldDataFields); + if (hasFieldDataFields) { + out.writeVInt(fieldDataFields.size()); + for (String fieldName : fieldDataFields) { + out.writeString(fieldName); + } + } + boolean hasFieldNames = fieldNames != null; + out.writeBoolean(hasFieldNames); + if (hasFieldNames) { + out.writeVInt(fieldNames.size()); + for (String fieldName : fieldNames) { + out.writeString(fieldName); + } + } + out.writeVInt(from); + boolean hasHighlighter = highlightBuilder != null; + out.writeBoolean(hasHighlighter); + if (hasHighlighter) { + highlightBuilder.writeTo(out); + } + boolean hasScriptFields = scriptFields != null; + out.writeBoolean(hasScriptFields); + if (hasScriptFields) { + out.writeVInt(scriptFields.size()); + for (ScriptField scriptField : scriptFields) { + scriptField.writeTo(out); + } + } + out.writeVInt(size); + boolean hasSorts = sorts != null; + out.writeBoolean(hasSorts); + if (hasSorts) { + out.writeVInt(sorts.size()); + for (BytesReference sort : sorts) { + out.writeBytesReference(sort); + } + } + out.writeBoolean(trackScores); + out.writeBoolean(version); + } + + @Override + protected int doHashCode() { + return Objects.hash(explain, fetchSourceContext, fieldDataFields, fieldNames, from, highlightBuilder, scriptFields, size, sorts, + trackScores, version); + } + + @Override + protected boolean doEquals(Object obj) { + TopHitsAggregatorBuilder other = (TopHitsAggregatorBuilder) obj; + return Objects.equals(explain, other.explain) + && Objects.equals(fetchSourceContext, other.fetchSourceContext) + && Objects.equals(fieldDataFields, other.fieldDataFields) + && Objects.equals(fieldNames, other.fieldNames) + && Objects.equals(from, other.from) + && Objects.equals(highlightBuilder, other.highlightBuilder) + && Objects.equals(scriptFields, other.scriptFields) + && Objects.equals(size, other.size) + && Objects.equals(sorts, other.sorts) + && Objects.equals(trackScores, other.trackScores) + && Objects.equals(version, other.version); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsParser.java index ba580acf692..03921d620ee 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsParser.java @@ -45,9 +45,9 @@ public class TopHitsParser implements Aggregator.Parser { } @Override - public TopHitsAggregator.TopHitsAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) + public TopHitsAggregatorBuilder parse(String aggregationName, XContentParser parser, QueryParseContext context) throws IOException { - TopHitsAggregator.TopHitsAggregatorBuilder factory = new TopHitsAggregator.TopHitsAggregatorBuilder(aggregationName); + TopHitsAggregatorBuilder factory = new TopHitsAggregatorBuilder(aggregationName); XContentParser.Token token; String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -178,8 +178,8 @@ public class TopHitsParser implements Aggregator.Parser { } @Override - public TopHitsAggregator.TopHitsAggregatorBuilder getFactoryPrototypes() { - return TopHitsAggregator.TopHitsAggregatorBuilder.PROTOTYPE; + public TopHitsAggregatorBuilder getFactoryPrototypes() { + return TopHitsAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java index b47a9f927b5..a25f7dea70e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java @@ -19,27 +19,18 @@ package org.elasticsearch.search.aggregations.metrics.valuecount; import org.apache.lucene.index.LeafReaderContext; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.LongArray; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.search.aggregations.Aggregator; -import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; -import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; @@ -115,47 +106,4 @@ public class ValueCountAggregator extends NumericMetricsAggregator.SingleValue { Releasables.close(counts); } - public static class ValueCountAggregatorBuilder - extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final ValueCountAggregatorBuilder PROTOTYPE = new ValueCountAggregatorBuilder("", null); - - public ValueCountAggregatorBuilder(String name, ValueType targetValueType) { - super(name, InternalValueCount.TYPE, ValuesSourceType.ANY, targetValueType); - } - - @Override - protected ValueCountAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, - AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder) throws IOException { - return new ValueCountAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); - } - - @Override - protected ValuesSourceAggregatorBuilder innerReadFrom(String name, - ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in) { - return new ValueCountAggregator.ValueCountAggregatorBuilder(name, targetValueType); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - - @Override - public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(Object obj) { - return true; - } - - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregatorBuilder.java new file mode 100644 index 00000000000..d062b45380f --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregatorBuilder.java @@ -0,0 +1,77 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.metrics.valuecount; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactories; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.support.AggregationContext; +import org.elasticsearch.search.aggregations.support.ValueType; +import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; +import org.elasticsearch.search.aggregations.support.ValuesSourceType; + +import java.io.IOException; + +public class ValueCountAggregatorBuilder + extends ValuesSourceAggregatorBuilder.LeafOnly { + + static final ValueCountAggregatorBuilder PROTOTYPE = new ValueCountAggregatorBuilder("", null); + + public ValueCountAggregatorBuilder(String name, ValueType targetValueType) { + super(name, InternalValueCount.TYPE, ValuesSourceType.ANY, targetValueType); + } + + @Override + protected ValueCountAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, + AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder) throws IOException { + return new ValueCountAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); + } + + @Override + protected ValuesSourceAggregatorBuilder innerReadFrom(String name, + ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in) { + return new ValueCountAggregatorBuilder(name, targetValueType); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(Object obj) { + return true; + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountParser.java index 7fefcf6f741..52d37d1be8c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountParser.java @@ -51,13 +51,13 @@ public class ValueCountParser extends AnyValuesSourceParser { } @Override - protected ValuesSourceAggregatorBuilder createFactory( + protected ValuesSourceAggregatorBuilder createFactory( String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { - return new ValueCountAggregator.ValueCountAggregatorBuilder(aggregationName, targetValueType); + return new ValueCountAggregatorBuilder(aggregationName, targetValueType); } @Override - public ValueCountAggregator.ValueCountAggregatorBuilder getFactoryPrototypes() { - return ValueCountAggregator.ValueCountAggregatorBuilder.PROTOTYPE; + public ValueCountAggregatorBuilder getFactoryPrototypes() { + return ValueCountAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilders.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilders.java index 5087835bd4a..9d97fd6af8f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilders.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilders.java @@ -20,19 +20,19 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.script.Script; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.having.BucketSelectorPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregatorBuilder; import java.util.Map; @@ -41,70 +41,70 @@ public final class PipelineAggregatorBuilders { private PipelineAggregatorBuilders() { } - public static final DerivativePipelineAggregator.DerivativePipelineAggregatorBuilder derivative(String name, String bucketsPath) { - return new DerivativePipelineAggregator.DerivativePipelineAggregatorBuilder(name, bucketsPath); + public static final DerivativePipelineAggregatorBuilder derivative(String name, String bucketsPath) { + return new DerivativePipelineAggregatorBuilder(name, bucketsPath); } - public static final MaxBucketPipelineAggregator.MaxBucketPipelineAggregatorBuilder maxBucket(String name, String bucketsPath) { - return new MaxBucketPipelineAggregator.MaxBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final MaxBucketPipelineAggregatorBuilder maxBucket(String name, String bucketsPath) { + return new MaxBucketPipelineAggregatorBuilder(name, bucketsPath); } - public static final MinBucketPipelineAggregator.MinBucketPipelineAggregatorBuilder minBucket(String name, String bucketsPath) { - return new MinBucketPipelineAggregator.MinBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final MinBucketPipelineAggregatorBuilder minBucket(String name, String bucketsPath) { + return new MinBucketPipelineAggregatorBuilder(name, bucketsPath); } - public static final AvgBucketPipelineAggregator.AvgBucketPipelineAggregatorBuilder avgBucket(String name, String bucketsPath) { - return new AvgBucketPipelineAggregator.AvgBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final AvgBucketPipelineAggregatorBuilder avgBucket(String name, String bucketsPath) { + return new AvgBucketPipelineAggregatorBuilder(name, bucketsPath); } - public static final SumBucketPipelineAggregator.SumBucketPipelineAggregatorBuilder sumBucket(String name, String bucketsPath) { - return new SumBucketPipelineAggregator.SumBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final SumBucketPipelineAggregatorBuilder sumBucket(String name, String bucketsPath) { + return new SumBucketPipelineAggregatorBuilder(name, bucketsPath); } - public static final StatsBucketPipelineAggregator.StatsBucketPipelineAggregatorBuilder statsBucket(String name, String bucketsPath) { - return new StatsBucketPipelineAggregator.StatsBucketPipelineAggregatorBuilder(name, bucketsPath); + public static final StatsBucketPipelineAggregatorBuilder statsBucket(String name, String bucketsPath) { + return new StatsBucketPipelineAggregatorBuilder(name, bucketsPath); } - public static final ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder extendedStatsBucket(String name, + public static final ExtendedStatsBucketPipelineAggregatorBuilder extendedStatsBucket(String name, String bucketsPath) { - return new ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder(name, bucketsPath); + return new ExtendedStatsBucketPipelineAggregatorBuilder(name, bucketsPath); } - public static final PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder percentilesBucket(String name, + public static final PercentilesBucketPipelineAggregatorBuilder percentilesBucket(String name, String bucketsPath) { - return new PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder(name, bucketsPath); + return new PercentilesBucketPipelineAggregatorBuilder(name, bucketsPath); } - public static final MovAvgPipelineAggregator.MovAvgPipelineAggregatorBuilder movingAvg(String name, String bucketsPath) { - return new MovAvgPipelineAggregator.MovAvgPipelineAggregatorBuilder(name, bucketsPath); + public static final MovAvgPipelineAggregatorBuilder movingAvg(String name, String bucketsPath) { + return new MovAvgPipelineAggregatorBuilder(name, bucketsPath); } - public static final BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder bucketScript(String name, + public static final BucketScriptPipelineAggregatorBuilder bucketScript(String name, Map bucketsPathsMap, Script script) { - return new BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder(name, bucketsPathsMap, script); + return new BucketScriptPipelineAggregatorBuilder(name, bucketsPathsMap, script); } - public static final BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder bucketScript(String name, Script script, + public static final BucketScriptPipelineAggregatorBuilder bucketScript(String name, Script script, String... bucketsPaths) { - return new BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder(name, script, bucketsPaths); + return new BucketScriptPipelineAggregatorBuilder(name, script, bucketsPaths); } - public static final BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder bucketSelector(String name, + public static final BucketSelectorPipelineAggregatorBuilder bucketSelector(String name, Map bucketsPathsMap, Script script) { - return new BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder(name, bucketsPathsMap, script); + return new BucketSelectorPipelineAggregatorBuilder(name, bucketsPathsMap, script); } - public static final BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder bucketSelector(String name, Script script, + public static final BucketSelectorPipelineAggregatorBuilder bucketSelector(String name, Script script, String... bucketsPaths) { - return new BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder(name, script, bucketsPaths); + return new BucketSelectorPipelineAggregatorBuilder(name, script, bucketsPaths); } - public static final CumulativeSumPipelineAggregator.CumulativeSumPipelineAggregatorBuilder cumulativeSum(String name, + public static final CumulativeSumPipelineAggregatorBuilder cumulativeSum(String name, String bucketsPath) { - return new CumulativeSumPipelineAggregator.CumulativeSumPipelineAggregatorBuilder(name, bucketsPath); + return new CumulativeSumPipelineAggregatorBuilder(name, bucketsPath); } - public static final SerialDiffPipelineAggregator.SerialDiffPipelineAggregatorBuilder diff(String name, String bucketsPath) { - return new SerialDiffPipelineAggregator.SerialDiffPipelineAggregatorBuilder(name, bucketsPath); + public static final SerialDiffPipelineAggregatorBuilder diff(String name, String bucketsPath) { + return new SerialDiffPipelineAggregatorBuilder(name, bucketsPath); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java index 93d02bc7207..f352f7ab289 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java @@ -30,13 +30,13 @@ public class AvgBucketParser extends BucketMetricsParser { } @Override - protected AvgBucketPipelineAggregator.AvgBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, + protected AvgBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map unparsedParams) { - return new AvgBucketPipelineAggregator.AvgBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new AvgBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); } @Override - public AvgBucketPipelineAggregator.AvgBucketPipelineAggregatorBuilder getFactoryPrototype() { - return AvgBucketPipelineAggregator.AvgBucketPipelineAggregatorBuilder.PROTOTYPE; + public AvgBucketPipelineAggregatorBuilder getFactoryPrototype() { + return AvgBucketPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregator.java index 3fbdb48fd02..7210bdb2106 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregator.java @@ -20,17 +20,12 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; @@ -89,57 +84,4 @@ public class AvgBucketPipelineAggregator extends BucketMetricsPipelineAggregator return new InternalSimpleValue(name(), avgValue, formatter, pipelineAggregators, metadata); } - public static class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { - - static final AvgBucketPipelineAggregatorBuilder PROTOTYPE = new AvgBucketPipelineAggregatorBuilder("", ""); - - public AvgBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private AvgBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new AvgBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatorFactories) { - if (bucketsPaths.length != 1) { - throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected AvgBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { - return new AvgBucketPipelineAggregatorBuilder(name, bucketsPaths); - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - // Do nothing, no extra state to write to stream - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { - return true; - } - - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..1d62dfe10d7 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java @@ -0,0 +1,85 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder { + + static final AvgBucketPipelineAggregatorBuilder PROTOTYPE = new AvgBucketPipelineAggregatorBuilder("", ""); + + public AvgBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private AvgBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, AvgBucketPipelineAggregator.TYPE.name(), bucketsPaths); + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new AvgBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatorFactories) { + if (bucketsPaths.length != 1) { + throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected AvgBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { + return new AvgBucketPipelineAggregatorBuilder(name, bucketsPaths); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + // Do nothing, no extra state to write to stream + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + return true; + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java index ff2e11e7998..51393e7e082 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java @@ -31,14 +31,14 @@ public class MaxBucketParser extends BucketMetricsParser { } @Override - protected MaxBucketPipelineAggregator.MaxBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, + protected MaxBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map unparsedParams) { - return new MaxBucketPipelineAggregator.MaxBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new MaxBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); } @Override - public MaxBucketPipelineAggregator.MaxBucketPipelineAggregatorBuilder getFactoryPrototype() { - return MaxBucketPipelineAggregator.MaxBucketPipelineAggregatorBuilder.PROTOTYPE; + public MaxBucketPipelineAggregatorBuilder getFactoryPrototype() { + return MaxBucketPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregator.java index 8008987199b..e4cd5569ec2 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregator.java @@ -20,16 +20,11 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; @@ -96,59 +91,4 @@ public class MaxBucketPipelineAggregator extends BucketMetricsPipelineAggregator return new InternalBucketMetricValue(name(), keys, maxValue, formatter, Collections.emptyList(), metaData()); } - public static class MaxBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { - - static final MaxBucketPipelineAggregatorBuilder PROTOTYPE = new MaxBucketPipelineAggregatorBuilder("", ""); - - public MaxBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private MaxBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new MaxBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatorFactories) { - if (bucketsPaths.length != 1) { - throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected MaxBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - return new MaxBucketPipelineAggregatorBuilder(name, bucketsPaths); - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - // Do nothing, no extra state to write to stream - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { - return true; - } - - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..ea9e3efb8fb --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java @@ -0,0 +1,87 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class MaxBucketPipelineAggregatorBuilder + extends BucketMetricsPipelineAggregatorBuilder { + + static final MaxBucketPipelineAggregatorBuilder PROTOTYPE = new MaxBucketPipelineAggregatorBuilder("", ""); + + public MaxBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private MaxBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, MaxBucketPipelineAggregator.TYPE.name(), bucketsPaths); + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new MaxBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatorFactories) { + if (bucketsPaths.length != 1) { + throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected MaxBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) + throws IOException { + return new MaxBucketPipelineAggregatorBuilder(name, bucketsPaths); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + // Do nothing, no extra state to write to stream + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + return true; + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java index 3d5ba69c190..ea7c2284857 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java @@ -31,14 +31,14 @@ public class MinBucketParser extends BucketMetricsParser { } @Override - protected MinBucketPipelineAggregator.MinBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, + protected MinBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map unparsedParams) { - return new MinBucketPipelineAggregator.MinBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new MinBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); } @Override - public MinBucketPipelineAggregator.MinBucketPipelineAggregatorBuilder getFactoryPrototype() { - return MinBucketPipelineAggregator.MinBucketPipelineAggregatorBuilder.PROTOTYPE; + public MinBucketPipelineAggregatorBuilder getFactoryPrototype() { + return MinBucketPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregator.java index f700de16e67..108ee0d2a7d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregator.java @@ -20,16 +20,11 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; @@ -95,61 +90,6 @@ public class MinBucketPipelineAggregator extends BucketMetricsPipelineAggregator java.util.Map metadata) { String[] keys = minBucketKeys.toArray(new String[minBucketKeys.size()]); return new InternalBucketMetricValue(name(), keys, minValue, formatter, Collections.emptyList(), metaData()); - }; - - public static class MinBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { - - static final MinBucketPipelineAggregatorBuilder PROTOTYPE = new MinBucketPipelineAggregatorBuilder("", ""); - - public MinBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private MinBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new MinBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatorFactories) { - if (bucketsPaths.length != 1) { - throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected MinBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - return new MinBucketPipelineAggregatorBuilder(name, bucketsPaths); - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - // Do nothing, no extra state to write to stream - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { - return true; - } - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..50e5d978f26 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java @@ -0,0 +1,87 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class MinBucketPipelineAggregatorBuilder + extends BucketMetricsPipelineAggregatorBuilder { + + static final MinBucketPipelineAggregatorBuilder PROTOTYPE = new MinBucketPipelineAggregatorBuilder("", ""); + + public MinBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private MinBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, MinBucketPipelineAggregator.TYPE.name(), bucketsPaths); + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new MinBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatorFactories) { + if (bucketsPaths.length != 1) { + throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected MinBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) + throws IOException { + return new MinBucketPipelineAggregatorBuilder(name, bucketsPaths); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + // Do nothing, no extra state to write to stream + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + return true; + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java index 1cca9114a80..b1969afb558 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java @@ -37,7 +37,7 @@ public class PercentilesBucketParser extends BucketMetricsParser { } @Override - protected PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected PercentilesBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map unparsedParams) throws ParseException { double[] percents = null; @@ -63,8 +63,8 @@ public class PercentilesBucketParser extends BucketMetricsParser { } } - PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder factory = new - PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + PercentilesBucketPipelineAggregatorBuilder factory = new + PercentilesBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); if (percents != null) { factory.percents(percents); } @@ -72,7 +72,7 @@ public class PercentilesBucketParser extends BucketMetricsParser { } @Override - public PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder getFactoryPrototype() { - return PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder.PROTOTYPE; + public PercentilesBucketPipelineAggregatorBuilder getFactoryPrototype() { + return PercentilesBucketPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregator.java index a330074b491..1a4aa339d0d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregator.java @@ -22,25 +22,19 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAggregator { @@ -124,98 +118,4 @@ public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAg out.writeDoubleArray(percents); } - public static class PercentilesBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { - - static final PercentilesBucketPipelineAggregatorBuilder PROTOTYPE = new PercentilesBucketPipelineAggregatorBuilder("", ""); - - private double[] percents = new double[] { 1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0 }; - - public PercentilesBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private PercentilesBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - /** - * Get the percentages to calculate percentiles for in this aggregation - */ - public double[] percents() { - return percents; - } - - /** - * Set the percentages to calculate percentiles for in this aggregation - */ - public PercentilesBucketPipelineAggregatorBuilder percents(double[] percents) { - if (percents == null) { - throw new IllegalArgumentException("[percents] must not be null: [" + name + "]"); - } - for (Double p : percents) { - if (p == null || p < 0.0 || p > 100.0) { - throw new IllegalArgumentException(PercentilesBucketParser.PERCENTS.getPreferredName() - + " must only contain non-null doubles from 0.0-100.0 inclusive"); - } - } - this.percents = percents; - return this; - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new PercentilesBucketPipelineAggregator(name, percents, bucketsPaths, gapPolicy(), formatter(), metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatorFactories) { - if (bucketsPaths.length != 1) { - throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - - for (Double p : percents) { - if (p == null || p < 0.0 || p > 100.0) { - throw new IllegalStateException(PercentilesBucketParser.PERCENTS.getPreferredName() - + " must only contain non-null doubles from 0.0-100.0 inclusive"); - } - } - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - if (percents != null) { - builder.field(PercentilesBucketParser.PERCENTS.getPreferredName(), percents); - } - return builder; - } - - @Override - protected PercentilesBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - PercentilesBucketPipelineAggregatorBuilder factory = new PercentilesBucketPipelineAggregatorBuilder(name, bucketsPaths); - factory.percents = in.readDoubleArray(); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeDoubleArray(percents); - } - - @Override - protected int innerHashCode() { - return Arrays.hashCode(percents); - } - - @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder obj) { - PercentilesBucketPipelineAggregatorBuilder other = (PercentilesBucketPipelineAggregatorBuilder) obj; - return Objects.deepEquals(percents, other.percents); - } - - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..5f2d279a5f0 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java @@ -0,0 +1,128 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class PercentilesBucketPipelineAggregatorBuilder + extends BucketMetricsPipelineAggregatorBuilder { + + static final PercentilesBucketPipelineAggregatorBuilder PROTOTYPE = new PercentilesBucketPipelineAggregatorBuilder("", ""); + + private double[] percents = new double[] { 1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0 }; + + public PercentilesBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private PercentilesBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, PercentilesBucketPipelineAggregator.TYPE.name(), bucketsPaths); + } + + /** + * Get the percentages to calculate percentiles for in this aggregation + */ + public double[] percents() { + return percents; + } + + /** + * Set the percentages to calculate percentiles for in this aggregation + */ + public PercentilesBucketPipelineAggregatorBuilder percents(double[] percents) { + if (percents == null) { + throw new IllegalArgumentException("[percents] must not be null: [" + name + "]"); + } + for (Double p : percents) { + if (p == null || p < 0.0 || p > 100.0) { + throw new IllegalArgumentException(PercentilesBucketParser.PERCENTS.getPreferredName() + + " must only contain non-null doubles from 0.0-100.0 inclusive"); + } + } + this.percents = percents; + return this; + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new PercentilesBucketPipelineAggregator(name, percents, bucketsPaths, gapPolicy(), formatter(), metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatorFactories) { + if (bucketsPaths.length != 1) { + throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + + for (Double p : percents) { + if (p == null || p < 0.0 || p > 100.0) { + throw new IllegalStateException(PercentilesBucketParser.PERCENTS.getPreferredName() + + " must only contain non-null doubles from 0.0-100.0 inclusive"); + } + } + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + if (percents != null) { + builder.field(PercentilesBucketParser.PERCENTS.getPreferredName(), percents); + } + return builder; + } + + @Override + protected PercentilesBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) + throws IOException { + PercentilesBucketPipelineAggregatorBuilder factory = new PercentilesBucketPipelineAggregatorBuilder(name, bucketsPaths); + factory.percents = in.readDoubleArray(); + return factory; + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeDoubleArray(percents); + } + + @Override + protected int innerHashCode() { + return Arrays.hashCode(percents); + } + + @Override + protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder obj) { + PercentilesBucketPipelineAggregatorBuilder other = (PercentilesBucketPipelineAggregatorBuilder) obj; + return Objects.deepEquals(percents, other.percents); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java index adb6beca185..dd4215618d8 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java @@ -30,13 +30,13 @@ public class StatsBucketParser extends BucketMetricsParser { } @Override - protected StatsBucketPipelineAggregator.StatsBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected StatsBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map unparsedParams) { - return new StatsBucketPipelineAggregator.StatsBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new StatsBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); } @Override - public StatsBucketPipelineAggregator.StatsBucketPipelineAggregatorBuilder getFactoryPrototype() { - return StatsBucketPipelineAggregator.StatsBucketPipelineAggregatorBuilder.PROTOTYPE; + public StatsBucketPipelineAggregatorBuilder getFactoryPrototype() { + return StatsBucketPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregator.java index cf36bdf3a6a..41559640eac 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregator.java @@ -20,16 +20,11 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; @@ -95,59 +90,4 @@ public class StatsBucketPipelineAggregator extends BucketMetricsPipelineAggregat return new InternalStatsBucket(name(), count, sum, min, max, formatter, pipelineAggregators, metadata); } - public static class StatsBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { - - static final StatsBucketPipelineAggregatorBuilder PROTOTYPE = new StatsBucketPipelineAggregatorBuilder("", ""); - - public StatsBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private StatsBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new StatsBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatorFactories) { - if (bucketsPaths.length != 1) { - throw new IllegalStateException(Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected StatsBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - return new StatsBucketPipelineAggregatorBuilder(name, bucketsPaths); - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - // Do nothing, no extra state to write to stream - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { - return true; - } - - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..91fe885f93e --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java @@ -0,0 +1,88 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class StatsBucketPipelineAggregatorBuilder + extends BucketMetricsPipelineAggregatorBuilder { + + static final StatsBucketPipelineAggregatorBuilder PROTOTYPE = new StatsBucketPipelineAggregatorBuilder("", ""); + + public StatsBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private StatsBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, StatsBucketPipelineAggregator.TYPE.name(), bucketsPaths); + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new StatsBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatorFactories) { + if (bucketsPaths.length != 1) { + throw new IllegalStateException(Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected StatsBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) + throws IOException { + return new StatsBucketPipelineAggregatorBuilder(name, bucketsPaths); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + // Do nothing, no extra state to write to stream + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + return true; + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java index 2a2f9eb9031..996adfd6492 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java @@ -34,7 +34,7 @@ public class ExtendedStatsBucketParser extends BucketMetricsParser { } @Override - protected ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, + protected ExtendedStatsBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map unparsedParams) throws ParseException { Double sigma = null; @@ -49,8 +49,8 @@ public class ExtendedStatsBucketParser extends BucketMetricsParser { + param.getClass().getSimpleName() + "` provided instead", 0); } } - ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder factory = - new ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + ExtendedStatsBucketPipelineAggregatorBuilder factory = + new ExtendedStatsBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); if (sigma != null) { factory.sigma(sigma); } @@ -58,7 +58,7 @@ public class ExtendedStatsBucketParser extends BucketMetricsParser { } @Override - public ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder getFactoryPrototype() { - return ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder.PROTOTYPE; + public ExtendedStatsBucketPipelineAggregatorBuilder getFactoryPrototype() { + return ExtendedStatsBucketPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregator.java index 15f56dcb2f6..3f308465e37 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregator.java @@ -20,23 +20,17 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Objects; public class ExtendedStatsBucketPipelineAggregator extends BucketMetricsPipelineAggregator { @@ -101,90 +95,4 @@ public class ExtendedStatsBucketPipelineAggregator extends BucketMetricsPipeline return new InternalExtendedStatsBucket(name(), count, sum, min, max, sumOfSqrs, sigma, formatter, pipelineAggregators, metadata); } - public static class ExtendedStatsBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { - - static final ExtendedStatsBucketPipelineAggregatorBuilder PROTOTYPE = new ExtendedStatsBucketPipelineAggregatorBuilder("", ""); - - private double sigma = 2.0; - - public ExtendedStatsBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private ExtendedStatsBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - /** - * Set the value of sigma to use when calculating the standard deviation - * bounds - */ - public ExtendedStatsBucketPipelineAggregatorBuilder sigma(double sigma) { - if (sigma < 0.0) { - throw new IllegalArgumentException(ExtendedStatsBucketParser.SIGMA.getPreferredName() + " must be a non-negative double"); - } - this.sigma = sigma; - return this; - } - - /** - * Get the value of sigma to use when calculating the standard deviation - * bounds - */ - public double sigma() { - return sigma; - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new ExtendedStatsBucketPipelineAggregator(name, bucketsPaths, sigma, gapPolicy(), formatter(), metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatorFactories) { - if (bucketsPaths.length != 1) { - throw new IllegalStateException(Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - - if (sigma < 0.0 ) { - throw new IllegalStateException(ExtendedStatsBucketParser.SIGMA.getPreferredName() - + " must be a non-negative double"); - } - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - builder.field(ExtendedStatsBucketParser.SIGMA.getPreferredName(), sigma); - return builder; - } - - @Override - protected ExtendedStatsBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - ExtendedStatsBucketPipelineAggregatorBuilder factory = new ExtendedStatsBucketPipelineAggregatorBuilder(name, bucketsPaths); - factory.sigma = in.readDouble(); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeDouble(sigma); - } - - @Override - protected int innerHashCode() { - return Objects.hash(sigma); - } - - @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder obj) { - ExtendedStatsBucketPipelineAggregatorBuilder other = (ExtendedStatsBucketPipelineAggregatorBuilder) obj; - return Objects.equals(sigma, other.sigma); - } - - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..6121a49d133 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java @@ -0,0 +1,120 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class ExtendedStatsBucketPipelineAggregatorBuilder + extends BucketMetricsPipelineAggregatorBuilder { + + static final ExtendedStatsBucketPipelineAggregatorBuilder PROTOTYPE = new ExtendedStatsBucketPipelineAggregatorBuilder("", ""); + + private double sigma = 2.0; + + public ExtendedStatsBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private ExtendedStatsBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, ExtendedStatsBucketPipelineAggregator.TYPE.name(), bucketsPaths); + } + + /** + * Set the value of sigma to use when calculating the standard deviation + * bounds + */ + public ExtendedStatsBucketPipelineAggregatorBuilder sigma(double sigma) { + if (sigma < 0.0) { + throw new IllegalArgumentException(ExtendedStatsBucketParser.SIGMA.getPreferredName() + " must be a non-negative double"); + } + this.sigma = sigma; + return this; + } + + /** + * Get the value of sigma to use when calculating the standard deviation + * bounds + */ + public double sigma() { + return sigma; + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new ExtendedStatsBucketPipelineAggregator(name, bucketsPaths, sigma, gapPolicy(), formatter(), metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatorFactories) { + if (bucketsPaths.length != 1) { + throw new IllegalStateException(Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + + if (sigma < 0.0 ) { + throw new IllegalStateException(ExtendedStatsBucketParser.SIGMA.getPreferredName() + + " must be a non-negative double"); + } + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + builder.field(ExtendedStatsBucketParser.SIGMA.getPreferredName(), sigma); + return builder; + } + + @Override + protected ExtendedStatsBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) + throws IOException { + ExtendedStatsBucketPipelineAggregatorBuilder factory = new ExtendedStatsBucketPipelineAggregatorBuilder(name, bucketsPaths); + factory.sigma = in.readDouble(); + return factory; + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeDouble(sigma); + } + + @Override + protected int innerHashCode() { + return Objects.hash(sigma); + } + + @Override + protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder obj) { + ExtendedStatsBucketPipelineAggregatorBuilder other = (ExtendedStatsBucketPipelineAggregatorBuilder) obj; + return Objects.equals(sigma, other.sigma); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java index a0912523475..c4a17cd084d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java @@ -30,13 +30,13 @@ public class SumBucketParser extends BucketMetricsParser { } @Override - protected SumBucketPipelineAggregator.SumBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, + protected SumBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath, Map unparsedParams) { - return new SumBucketPipelineAggregator.SumBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); + return new SumBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath); } @Override - public SumBucketPipelineAggregator.SumBucketPipelineAggregatorBuilder getFactoryPrototype() { - return SumBucketPipelineAggregator.SumBucketPipelineAggregatorBuilder.PROTOTYPE; + public SumBucketPipelineAggregatorBuilder getFactoryPrototype() { + return SumBucketPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregator.java index 4c9ccf2e9d6..b16cec211ee 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregator.java @@ -20,17 +20,12 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; @@ -85,59 +80,4 @@ public class SumBucketPipelineAggregator extends BucketMetricsPipelineAggregator return new InternalSimpleValue(name(), sum, formatter, pipelineAggregators, metadata); } - public static class SumBucketPipelineAggregatorBuilder - extends BucketMetricsPipelineAggregatorBuilder { - - static final SumBucketPipelineAggregatorBuilder PROTOTYPE = new SumBucketPipelineAggregatorBuilder("", ""); - - public SumBucketPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private SumBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new SumBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatorFactories) { - if (bucketsPaths.length != 1) { - throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - } - - @Override - protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { - return builder; - } - - @Override - protected SumBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - return new SumBucketPipelineAggregatorBuilder(name, bucketsPaths); - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - // Do nothing, no extra state to write to stream - } - - @Override - protected int innerHashCode() { - return 0; - } - - @Override - protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { - return true; - } - - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..25a1ebe6f84 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java @@ -0,0 +1,87 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class SumBucketPipelineAggregatorBuilder + extends BucketMetricsPipelineAggregatorBuilder { + + static final SumBucketPipelineAggregatorBuilder PROTOTYPE = new SumBucketPipelineAggregatorBuilder("", ""); + + public SumBucketPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private SumBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, SumBucketPipelineAggregator.TYPE.name(), bucketsPaths); + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new SumBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatorFactories) { + if (bucketsPaths.length != 1) { + throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + } + + @Override + protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { + return builder; + } + + @Override + protected SumBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) + throws IOException { + return new SumBucketPipelineAggregatorBuilder(name, bucketsPaths); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + // Do nothing, no extra state to write to stream + } + + @Override + protected int innerHashCode() { + return 0; + } + + @Override + protected boolean innerEquals(BucketMetricsPipelineAggregatorBuilder other) { + return true; + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java index a51598fe5dc..9e34a311767 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java @@ -45,7 +45,7 @@ public class BucketScriptParser implements PipelineAggregator.Parser { } @Override - public BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder parse(String reducerName, XContentParser parser, + public BucketScriptPipelineAggregatorBuilder parse(String reducerName, XContentParser parser, QueryParseContext context) throws IOException { XContentParser.Token token; Script script = null; @@ -114,8 +114,8 @@ public class BucketScriptParser implements PipelineAggregator.Parser { + "] for series_arithmetic aggregation [" + reducerName + "]"); } - BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder factory = - new BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script); + BucketScriptPipelineAggregatorBuilder factory = + new BucketScriptPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script); if (format != null) { factory.format(format); } @@ -126,8 +126,8 @@ public class BucketScriptParser implements PipelineAggregator.Parser { } @Override - public BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder getFactoryPrototype() { - return BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder.PROTOTYPE; + public BucketScriptPipelineAggregatorBuilder getFactoryPrototype() { + return BucketScriptPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregator.java index 8d47f7361da..2c1919f35eb 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregator.java @@ -21,11 +21,9 @@ package org.elasticsearch.search.aggregations.pipeline.bucketscript; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; -import org.elasticsearch.script.Script.ScriptField; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.elasticsearch.search.aggregations.InternalAggregation; @@ -37,9 +35,7 @@ import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Buck import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.support.format.ValueFormat; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatterStreams; @@ -49,8 +45,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -160,136 +154,4 @@ public class BucketScriptPipelineAggregator extends PipelineAggregator { bucketsPathsMap = (Map) in.readGenericValue(); } - public static class BucketScriptPipelineAggregatorBuilder extends PipelineAggregatorBuilder { - - static final BucketScriptPipelineAggregatorBuilder PROTOTYPE = new BucketScriptPipelineAggregatorBuilder("", Collections.emptyMap(), - new Script("")); - - private final Script script; - private final Map bucketsPathsMap; - private String format = null; - private GapPolicy gapPolicy = GapPolicy.SKIP; - - public BucketScriptPipelineAggregatorBuilder(String name, Map bucketsPathsMap, Script script) { - super(name, TYPE.name(), bucketsPathsMap.values().toArray(new String[bucketsPathsMap.size()])); - this.bucketsPathsMap = bucketsPathsMap; - this.script = script; - } - - public BucketScriptPipelineAggregatorBuilder(String name, Script script, String... bucketsPaths) { - this(name, convertToBucketsPathMap(bucketsPaths), script); - } - - private static Map convertToBucketsPathMap(String[] bucketsPaths) { - Map bucketsPathsMap = new HashMap<>(); - for (int i = 0; i < bucketsPaths.length; i++) { - bucketsPathsMap.put("_value" + i, bucketsPaths[i]); - } - return bucketsPathsMap; - } - - /** - * Sets the format to use on the output of this aggregation. - */ - public BucketScriptPipelineAggregatorBuilder format(String format) { - if (format == null) { - throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); - } - this.format = format; - return this; - } - - /** - * Gets the format to use on the output of this aggregation. - */ - public String format() { - return format; - } - - protected ValueFormatter formatter() { - if (format != null) { - return ValueFormat.Patternable.Number.format(format).formatter(); - } else { - return ValueFormatter.RAW; - } - } - - /** - * Sets the gap policy to use for this aggregation. - */ - public BucketScriptPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { - if (gapPolicy == null) { - throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); - } - this.gapPolicy = gapPolicy; - return this; - } - - /** - * Gets the gap policy to use for this aggregation. - */ - public GapPolicy gapPolicy() { - return gapPolicy; - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new BucketScriptPipelineAggregator(name, bucketsPathsMap, script, formatter(), gapPolicy, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(BucketScriptParser.BUCKETS_PATH.getPreferredName(), bucketsPathsMap); - builder.field(ScriptField.SCRIPT.getPreferredName(), script); - if (format != null) { - builder.field(BucketScriptParser.FORMAT.getPreferredName(), format); - } - builder.field(BucketScriptParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); - return builder; - } - - @Override - protected boolean overrideBucketsPath() { - return true; - } - - @Override - protected BucketScriptPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { - Map bucketsPathsMap = new HashMap(); - int mapSize = in.readVInt(); - for (int i = 0; i < mapSize; i++) { - bucketsPathsMap.put(in.readString(), in.readString()); - } - Script script = Script.readScript(in); - BucketScriptPipelineAggregatorBuilder factory = new BucketScriptPipelineAggregatorBuilder(name, bucketsPathsMap, script); - factory.format = in.readOptionalString(); - factory.gapPolicy = GapPolicy.readFrom(in); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeVInt(bucketsPathsMap.size()); - for (Entry e : bucketsPathsMap.entrySet()) { - out.writeString(e.getKey()); - out.writeString(e.getValue()); - } - script.writeTo(out); - out.writeOptionalString(format); - gapPolicy.writeTo(out); - } - - @Override - protected int doHashCode() { - return Objects.hash(bucketsPathsMap, script, format, gapPolicy); - } - - @Override - protected boolean doEquals(Object obj) { - BucketScriptPipelineAggregatorBuilder other = (BucketScriptPipelineAggregatorBuilder) obj; - return Objects.equals(bucketsPathsMap, other.bucketsPathsMap) && Objects.equals(script, other.script) - && Objects.equals(format, other.format) && Objects.equals(gapPolicy, other.gapPolicy); - } - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..85bf0ee3332 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java @@ -0,0 +1,170 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.bucketscript; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.script.Script; +import org.elasticsearch.script.Script.ScriptField; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; +import org.elasticsearch.search.aggregations.support.format.ValueFormat; +import org.elasticsearch.search.aggregations.support.format.ValueFormatter; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Map.Entry; + +public class BucketScriptPipelineAggregatorBuilder extends PipelineAggregatorBuilder { + + static final BucketScriptPipelineAggregatorBuilder PROTOTYPE = new BucketScriptPipelineAggregatorBuilder("", Collections.emptyMap(), + new Script("")); + + private final Script script; + private final Map bucketsPathsMap; + private String format = null; + private GapPolicy gapPolicy = GapPolicy.SKIP; + + public BucketScriptPipelineAggregatorBuilder(String name, Map bucketsPathsMap, Script script) { + super(name, BucketScriptPipelineAggregator.TYPE.name(), bucketsPathsMap.values().toArray(new String[bucketsPathsMap.size()])); + this.bucketsPathsMap = bucketsPathsMap; + this.script = script; + } + + public BucketScriptPipelineAggregatorBuilder(String name, Script script, String... bucketsPaths) { + this(name, convertToBucketsPathMap(bucketsPaths), script); + } + + private static Map convertToBucketsPathMap(String[] bucketsPaths) { + Map bucketsPathsMap = new HashMap<>(); + for (int i = 0; i < bucketsPaths.length; i++) { + bucketsPathsMap.put("_value" + i, bucketsPaths[i]); + } + return bucketsPathsMap; + } + + /** + * Sets the format to use on the output of this aggregation. + */ + public BucketScriptPipelineAggregatorBuilder format(String format) { + if (format == null) { + throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); + } + this.format = format; + return this; + } + + /** + * Gets the format to use on the output of this aggregation. + */ + public String format() { + return format; + } + + protected ValueFormatter formatter() { + if (format != null) { + return ValueFormat.Patternable.Number.format(format).formatter(); + } else { + return ValueFormatter.RAW; + } + } + + /** + * Sets the gap policy to use for this aggregation. + */ + public BucketScriptPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + if (gapPolicy == null) { + throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); + } + this.gapPolicy = gapPolicy; + return this; + } + + /** + * Gets the gap policy to use for this aggregation. + */ + public GapPolicy gapPolicy() { + return gapPolicy; + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new BucketScriptPipelineAggregator(name, bucketsPathsMap, script, formatter(), gapPolicy, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + builder.field(BucketScriptParser.BUCKETS_PATH.getPreferredName(), bucketsPathsMap); + builder.field(ScriptField.SCRIPT.getPreferredName(), script); + if (format != null) { + builder.field(BucketScriptParser.FORMAT.getPreferredName(), format); + } + builder.field(BucketScriptParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); + return builder; + } + + @Override + protected boolean overrideBucketsPath() { + return true; + } + + @Override + protected BucketScriptPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { + Map bucketsPathsMap = new HashMap(); + int mapSize = in.readVInt(); + for (int i = 0; i < mapSize; i++) { + bucketsPathsMap.put(in.readString(), in.readString()); + } + Script script = Script.readScript(in); + BucketScriptPipelineAggregatorBuilder factory = new BucketScriptPipelineAggregatorBuilder(name, bucketsPathsMap, script); + factory.format = in.readOptionalString(); + factory.gapPolicy = GapPolicy.readFrom(in); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeVInt(bucketsPathsMap.size()); + for (Entry e : bucketsPathsMap.entrySet()) { + out.writeString(e.getKey()); + out.writeString(e.getValue()); + } + script.writeTo(out); + out.writeOptionalString(format); + gapPolicy.writeTo(out); + } + + @Override + protected int doHashCode() { + return Objects.hash(bucketsPathsMap, script, format, gapPolicy); + } + + @Override + protected boolean doEquals(Object obj) { + BucketScriptPipelineAggregatorBuilder other = (BucketScriptPipelineAggregatorBuilder) obj; + return Objects.equals(bucketsPathsMap, other.bucketsPathsMap) && Objects.equals(script, other.script) + && Objects.equals(format, other.format) && Objects.equals(gapPolicy, other.gapPolicy); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/having/BucketSelectorParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java similarity index 90% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/having/BucketSelectorParser.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java index 250f499032e..084f79da306 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/having/BucketSelectorParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.pipeline.having; +package org.elasticsearch.search.aggregations.pipeline.bucketselector; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParsingException; @@ -45,7 +45,7 @@ public class BucketSelectorParser implements PipelineAggregator.Parser { } @Override - public BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder parse(String reducerName, XContentParser parser, + public BucketSelectorPipelineAggregatorBuilder parse(String reducerName, XContentParser parser, QueryParseContext context) throws IOException { XContentParser.Token token; Script script = null; @@ -111,8 +111,8 @@ public class BucketSelectorParser implements PipelineAggregator.Parser { + "] for bucket_selector aggregation [" + reducerName + "]"); } - BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder factory = - new BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script); + BucketSelectorPipelineAggregatorBuilder factory = + new BucketSelectorPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script); if (gapPolicy != null) { factory.gapPolicy(gapPolicy); } @@ -121,8 +121,8 @@ public class BucketSelectorParser implements PipelineAggregator.Parser { } @Override - public BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder getFactoryPrototype() { - return BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder.PROTOTYPE; + public BucketSelectorPipelineAggregatorBuilder getFactoryPrototype() { + return BucketSelectorPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/having/BucketSelectorPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregator.java similarity index 52% rename from core/src/main/java/org/elasticsearch/search/aggregations/pipeline/having/BucketSelectorPipelineAggregator.java rename to core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregator.java index 952b04a5aee..a2dfdca669d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/having/BucketSelectorPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregator.java @@ -17,16 +17,14 @@ * under the License. */ -package org.elasticsearch.search.aggregations.pipeline.having; +package org.elasticsearch.search.aggregations.pipeline.bucketselector; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; -import org.elasticsearch.script.Script.ScriptField; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext; @@ -35,17 +33,14 @@ import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation; import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptParser; + import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; import static org.elasticsearch.search.aggregations.pipeline.BucketHelpers.resolveBucketValue; @@ -90,7 +85,8 @@ public class BucketSelectorPipelineAggregator extends PipelineAggregator { @Override public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) { - InternalMultiBucketAggregation originalAgg = (InternalMultiBucketAggregation) aggregation; + InternalMultiBucketAggregation originalAgg = + (InternalMultiBucketAggregation) aggregation; List buckets = originalAgg.getBuckets(); CompiledScript compiledScript = reduceContext.scriptService().compile(script, ScriptContext.Standard.AGGS, Collections.emptyMap()); @@ -138,106 +134,4 @@ public class BucketSelectorPipelineAggregator extends PipelineAggregator { bucketsPathsMap = (Map) in.readGenericValue(); } - public static class BucketSelectorPipelineAggregatorBuilder extends PipelineAggregatorBuilder { - - static final BucketSelectorPipelineAggregatorBuilder PROTOTYPE = new BucketSelectorPipelineAggregatorBuilder("", - Collections.emptyMap(), new Script("")); - - private Script script; - private GapPolicy gapPolicy = GapPolicy.SKIP; - private Map bucketsPathsMap; - - public BucketSelectorPipelineAggregatorBuilder(String name, Map bucketsPathsMap, Script script) { - super(name, TYPE.name(), bucketsPathsMap.values().toArray(new String[bucketsPathsMap.size()])); - this.bucketsPathsMap = bucketsPathsMap; - this.script = script; - } - - public BucketSelectorPipelineAggregatorBuilder(String name, Script script, String... bucketsPaths) { - this(name, convertToBucketsPathMap(bucketsPaths), script); - } - - private static Map convertToBucketsPathMap(String[] bucketsPaths) { - Map bucketsPathsMap = new HashMap<>(); - for (int i = 0; i < bucketsPaths.length; i++) { - bucketsPathsMap.put("_value" + i, bucketsPaths[i]); - } - return bucketsPathsMap; - } - - /** - * Sets the gap policy to use for this aggregation. - */ - public BucketSelectorPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { - if (gapPolicy == null) { - throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); - } - this.gapPolicy = gapPolicy; - return this; - } - - /** - * Gets the gap policy to use for this aggregation. - */ - public GapPolicy gapPolicy() { - return gapPolicy; - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new BucketSelectorPipelineAggregator(name, bucketsPathsMap, script, gapPolicy, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(BucketScriptParser.BUCKETS_PATH.getPreferredName(), bucketsPathsMap); - builder.field(ScriptField.SCRIPT.getPreferredName(), script); - builder.field(BucketScriptParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); - return builder; - } - - @Override - protected boolean overrideBucketsPath() { - return true; - } - - @Override - protected BucketSelectorPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - Map bucketsPathsMap = new HashMap(); - int mapSize = in.readVInt(); - for (int i = 0; i < mapSize; i++) { - bucketsPathsMap.put(in.readString(), in.readString()); - } - Script script = Script.readScript(in); - BucketSelectorPipelineAggregatorBuilder factory = new BucketSelectorPipelineAggregatorBuilder(name, bucketsPathsMap, script); - factory.gapPolicy = GapPolicy.readFrom(in); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeVInt(bucketsPathsMap.size()); - for (Entry e : bucketsPathsMap.entrySet()) { - out.writeString(e.getKey()); - out.writeString(e.getValue()); - } - script.writeTo(out); - gapPolicy.writeTo(out); - } - - @Override - protected int doHashCode() { - return Objects.hash(bucketsPathsMap, script, gapPolicy); - } - - @Override - protected boolean doEquals(Object obj) { - BucketSelectorPipelineAggregatorBuilder other = (BucketSelectorPipelineAggregatorBuilder) obj; - return Objects.equals(bucketsPathsMap, other.bucketsPathsMap) && Objects.equals(script, other.script) - && Objects.equals(gapPolicy, other.gapPolicy); - } - - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..0def3374323 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java @@ -0,0 +1,139 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.bucketselector; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.script.Script; +import org.elasticsearch.script.Script.ScriptField; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; +import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptParser; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Map.Entry; + +public class BucketSelectorPipelineAggregatorBuilder extends PipelineAggregatorBuilder { + + static final BucketSelectorPipelineAggregatorBuilder PROTOTYPE = new BucketSelectorPipelineAggregatorBuilder("", + Collections.emptyMap(), new Script("")); + + private Script script; + private GapPolicy gapPolicy = GapPolicy.SKIP; + private Map bucketsPathsMap; + + public BucketSelectorPipelineAggregatorBuilder(String name, Map bucketsPathsMap, Script script) { + super(name, BucketSelectorPipelineAggregator.TYPE.name(), bucketsPathsMap.values().toArray(new String[bucketsPathsMap.size()])); + this.bucketsPathsMap = bucketsPathsMap; + this.script = script; + } + + public BucketSelectorPipelineAggregatorBuilder(String name, Script script, String... bucketsPaths) { + this(name, convertToBucketsPathMap(bucketsPaths), script); + } + + private static Map convertToBucketsPathMap(String[] bucketsPaths) { + Map bucketsPathsMap = new HashMap<>(); + for (int i = 0; i < bucketsPaths.length; i++) { + bucketsPathsMap.put("_value" + i, bucketsPaths[i]); + } + return bucketsPathsMap; + } + + /** + * Sets the gap policy to use for this aggregation. + */ + public BucketSelectorPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + if (gapPolicy == null) { + throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); + } + this.gapPolicy = gapPolicy; + return this; + } + + /** + * Gets the gap policy to use for this aggregation. + */ + public GapPolicy gapPolicy() { + return gapPolicy; + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new BucketSelectorPipelineAggregator(name, bucketsPathsMap, script, gapPolicy, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + builder.field(BucketScriptParser.BUCKETS_PATH.getPreferredName(), bucketsPathsMap); + builder.field(ScriptField.SCRIPT.getPreferredName(), script); + builder.field(BucketScriptParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); + return builder; + } + + @Override + protected boolean overrideBucketsPath() { + return true; + } + + @Override + protected BucketSelectorPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) + throws IOException { + Map bucketsPathsMap = new HashMap(); + int mapSize = in.readVInt(); + for (int i = 0; i < mapSize; i++) { + bucketsPathsMap.put(in.readString(), in.readString()); + } + Script script = Script.readScript(in); + BucketSelectorPipelineAggregatorBuilder factory = new BucketSelectorPipelineAggregatorBuilder(name, bucketsPathsMap, script); + factory.gapPolicy = GapPolicy.readFrom(in); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeVInt(bucketsPathsMap.size()); + for (Entry e : bucketsPathsMap.entrySet()) { + out.writeString(e.getKey()); + out.writeString(e.getValue()); + } + script.writeTo(out); + gapPolicy.writeTo(out); + } + + @Override + protected int doHashCode() { + return Objects.hash(bucketsPathsMap, script, gapPolicy); + } + + @Override + protected boolean doEquals(Object obj) { + BucketSelectorPipelineAggregatorBuilder other = (BucketSelectorPipelineAggregatorBuilder) obj; + return Objects.equals(bucketsPathsMap, other.bucketsPathsMap) && Objects.equals(script, other.script) + && Objects.equals(gapPolicy, other.gapPolicy); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java index 862a9673924..fc133f28cb6 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java @@ -40,7 +40,7 @@ public class CumulativeSumParser implements PipelineAggregator.Parser { } @Override - public CumulativeSumPipelineAggregator.CumulativeSumPipelineAggregatorBuilder parse(String pipelineAggregatorName, + public CumulativeSumPipelineAggregatorBuilder parse(String pipelineAggregatorName, XContentParser parser, QueryParseContext context) throws IOException { XContentParser.Token token; String currentFieldName = null; @@ -82,8 +82,8 @@ public class CumulativeSumParser implements PipelineAggregator.Parser { + "] for derivative aggregation [" + pipelineAggregatorName + "]"); } - CumulativeSumPipelineAggregator.CumulativeSumPipelineAggregatorBuilder factory = - new CumulativeSumPipelineAggregator.CumulativeSumPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); + CumulativeSumPipelineAggregatorBuilder factory = + new CumulativeSumPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); if (format != null) { factory.format(format); } @@ -91,8 +91,8 @@ public class CumulativeSumParser implements PipelineAggregator.Parser { } @Override - public CumulativeSumPipelineAggregator.CumulativeSumPipelineAggregatorBuilder getFactoryPrototype() { - return CumulativeSumPipelineAggregator.CumulativeSumPipelineAggregatorBuilder.PROTOTYPE; + public CumulativeSumPipelineAggregatorBuilder getFactoryPrototype() { + return CumulativeSumPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregator.java index 367b1f986b9..46727f165fd 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregator.java @@ -21,21 +21,15 @@ package org.elasticsearch.search.aggregations.pipeline.cumulativesum; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregations; -import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.support.format.ValueFormat; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatterStreams; @@ -43,7 +37,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -110,101 +103,4 @@ public class CumulativeSumPipelineAggregator extends PipelineAggregator { public void doWriteTo(StreamOutput out) throws IOException { ValueFormatterStreams.writeOptional(formatter, out); } - - public static class CumulativeSumPipelineAggregatorBuilder extends PipelineAggregatorBuilder { - - static final CumulativeSumPipelineAggregatorBuilder PROTOTYPE = new CumulativeSumPipelineAggregatorBuilder("", ""); - - private String format; - - public CumulativeSumPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private CumulativeSumPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - /** - * Sets the format to use on the output of this aggregation. - */ - public CumulativeSumPipelineAggregatorBuilder format(String format) { - if (format == null) { - throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); - } - this.format = format; - return this; - } - - /** - * Gets the format to use on the output of this aggregation. - */ - public String format() { - return format; - } - - protected ValueFormatter formatter() { - if (format != null) { - return ValueFormat.Patternable.Number.format(format).formatter(); - } else { - return ValueFormatter.RAW; - } - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new CumulativeSumPipelineAggregator(name, bucketsPaths, formatter(), metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatorFactories) { - if (bucketsPaths.length != 1) { - throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - if (!(parent instanceof AbstractHistogramAggregatorFactory)) { - throw new IllegalStateException("cumulative sum aggregation [" + name - + "] must have a histogram or date_histogram as parent"); - } else { - AbstractHistogramAggregatorFactory histoParent = (AbstractHistogramAggregatorFactory) parent; - if (histoParent.minDocCount() != 0) { - throw new IllegalStateException("parent histogram of cumulative sum aggregation [" + name - + "] must have min_doc_count of 0"); - } - } - } - - @Override - protected final XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - if (format != null) { - builder.field(BucketMetricsParser.FORMAT.getPreferredName(), format); - } - return builder; - } - - @Override - protected final CumulativeSumPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) - throws IOException { - CumulativeSumPipelineAggregatorBuilder factory = new CumulativeSumPipelineAggregatorBuilder(name, bucketsPaths); - factory.format = in.readOptionalString(); - return factory; - } - - @Override - protected final void doWriteTo(StreamOutput out) throws IOException { - out.writeOptionalString(format); - } - - @Override - protected int doHashCode() { - return Objects.hash(format); - } - - @Override - protected boolean doEquals(Object obj) { - CumulativeSumPipelineAggregatorBuilder other = (CumulativeSumPipelineAggregatorBuilder) obj; - return Objects.equals(format, other.format); - } - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..ae50998d290 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java @@ -0,0 +1,133 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.cumulativesum; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; +import org.elasticsearch.search.aggregations.support.format.ValueFormat; +import org.elasticsearch.search.aggregations.support.format.ValueFormatter; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class CumulativeSumPipelineAggregatorBuilder extends PipelineAggregatorBuilder { + + static final CumulativeSumPipelineAggregatorBuilder PROTOTYPE = new CumulativeSumPipelineAggregatorBuilder("", ""); + + private String format; + + public CumulativeSumPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private CumulativeSumPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, CumulativeSumPipelineAggregator.TYPE.name(), bucketsPaths); + } + + /** + * Sets the format to use on the output of this aggregation. + */ + public CumulativeSumPipelineAggregatorBuilder format(String format) { + if (format == null) { + throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); + } + this.format = format; + return this; + } + + /** + * Gets the format to use on the output of this aggregation. + */ + public String format() { + return format; + } + + protected ValueFormatter formatter() { + if (format != null) { + return ValueFormat.Patternable.Number.format(format).formatter(); + } else { + return ValueFormatter.RAW; + } + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new CumulativeSumPipelineAggregator(name, bucketsPaths, formatter(), metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatorFactories) { + if (bucketsPaths.length != 1) { + throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + if (!(parent instanceof AbstractHistogramAggregatorFactory)) { + throw new IllegalStateException("cumulative sum aggregation [" + name + + "] must have a histogram or date_histogram as parent"); + } else { + AbstractHistogramAggregatorFactory histoParent = (AbstractHistogramAggregatorFactory) parent; + if (histoParent.minDocCount() != 0) { + throw new IllegalStateException("parent histogram of cumulative sum aggregation [" + name + + "] must have min_doc_count of 0"); + } + } + } + + @Override + protected final XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + if (format != null) { + builder.field(BucketMetricsParser.FORMAT.getPreferredName(), format); + } + return builder; + } + + @Override + protected final CumulativeSumPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) + throws IOException { + CumulativeSumPipelineAggregatorBuilder factory = new CumulativeSumPipelineAggregatorBuilder(name, bucketsPaths); + factory.format = in.readOptionalString(); + return factory; + } + + @Override + protected final void doWriteTo(StreamOutput out) throws IOException { + out.writeOptionalString(format); + } + + @Override + protected int doHashCode() { + return Objects.hash(format); + } + + @Override + protected boolean doEquals(Object obj) { + CumulativeSumPipelineAggregatorBuilder other = (CumulativeSumPipelineAggregatorBuilder) obj; + return Objects.equals(format, other.format); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativeParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativeParser.java index cda162012fc..eb2dbeb0070 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativeParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativeParser.java @@ -41,7 +41,7 @@ public class DerivativeParser implements PipelineAggregator.Parser { } @Override - public DerivativePipelineAggregator.DerivativePipelineAggregatorBuilder parse(String pipelineAggregatorName, XContentParser parser, + public DerivativePipelineAggregatorBuilder parse(String pipelineAggregatorName, XContentParser parser, QueryParseContext context) throws IOException { XContentParser.Token token; String currentFieldName = null; @@ -89,8 +89,8 @@ public class DerivativeParser implements PipelineAggregator.Parser { + "] for derivative aggregation [" + pipelineAggregatorName + "]"); } - DerivativePipelineAggregator.DerivativePipelineAggregatorBuilder factory = - new DerivativePipelineAggregator.DerivativePipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); + DerivativePipelineAggregatorBuilder factory = + new DerivativePipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); if (format != null) { factory.format(format); } @@ -104,8 +104,8 @@ public class DerivativeParser implements PipelineAggregator.Parser { } @Override - public DerivativePipelineAggregator.DerivativePipelineAggregatorBuilder getFactoryPrototype() { - return DerivativePipelineAggregator.DerivativePipelineAggregatorBuilder.PROTOTYPE; + public DerivativePipelineAggregatorBuilder getFactoryPrototype() { + return DerivativePipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregator.java index 55b1d8a3ce2..1289da661c2 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregator.java @@ -21,24 +21,15 @@ package org.elasticsearch.search.aggregations.pipeline.derivative; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.rounding.DateTimeUnit; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregationExecutionException; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregations; -import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; -import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregatorFactory; -import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.support.format.ValueFormat; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatterStreams; import org.joda.time.DateTime; @@ -47,7 +38,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -158,164 +148,4 @@ public class DerivativePipelineAggregator extends PipelineAggregator { out.writeDouble(xAxisUnits); } } - - public static class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuilder { - - static final DerivativePipelineAggregatorBuilder PROTOTYPE = new DerivativePipelineAggregatorBuilder("", ""); - - private String format; - private GapPolicy gapPolicy = GapPolicy.SKIP; - private String units; - - public DerivativePipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private DerivativePipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - public DerivativePipelineAggregatorBuilder format(String format) { - if (format == null) { - throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); - } - this.format = format; - return this; - } - - public String format() { - return format; - } - - public DerivativePipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { - if (gapPolicy == null) { - throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); - } - this.gapPolicy = gapPolicy; - return this; - } - - public GapPolicy gapPolicy() { - return gapPolicy; - } - - public DerivativePipelineAggregatorBuilder unit(String units) { - if (units == null) { - throw new IllegalArgumentException("[units] must not be null: [" + name + "]"); - } - this.units = units; - return this; - } - - public DerivativePipelineAggregatorBuilder unit(DateHistogramInterval units) { - if (units == null) { - throw new IllegalArgumentException("[units] must not be null: [" + name + "]"); - } - this.units = units.toString(); - return this; - } - - public String unit() { - return units; - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - ValueFormatter formatter; - if (format != null) { - formatter = ValueFormat.Patternable.Number.format(format).formatter(); - } else { - formatter = ValueFormatter.RAW; - } - Long xAxisUnits = null; - if (units != null) { - DateTimeUnit dateTimeUnit = DateHistogramAggregatorFactory.DATE_FIELD_UNITS.get(units); - if (dateTimeUnit != null) { - xAxisUnits = dateTimeUnit.field().getDurationField().getUnitMillis(); - } else { - TimeValue timeValue = TimeValue.parseTimeValue(units, null, getClass().getSimpleName() + ".unit"); - if (timeValue != null) { - xAxisUnits = timeValue.getMillis(); - } - } - } - return new DerivativePipelineAggregator(name, bucketsPaths, formatter, gapPolicy, xAxisUnits, metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatoractories) { - if (bucketsPaths.length != 1) { - throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - if (!(parent instanceof AbstractHistogramAggregatorFactory)) { - throw new IllegalStateException("derivative aggregation [" + name - + "] must have a histogram or date_histogram as parent"); - } else { - AbstractHistogramAggregatorFactory histoParent = (AbstractHistogramAggregatorFactory) parent; - if (histoParent.minDocCount() != 0) { - throw new IllegalStateException("parent histogram of derivative aggregation [" + name - + "] must have min_doc_count of 0"); - } - } - } - - @Override - protected DerivativePipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { - DerivativePipelineAggregatorBuilder factory = new DerivativePipelineAggregatorBuilder(name, bucketsPaths); - factory.format = in.readOptionalString(); - if (in.readBoolean()) { - factory.gapPolicy = GapPolicy.readFrom(in); - } - factory.units = in.readOptionalString(); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeOptionalString(format); - boolean hasGapPolicy = gapPolicy != null; - out.writeBoolean(hasGapPolicy); - if (hasGapPolicy) { - gapPolicy.writeTo(out); - } - out.writeOptionalString(units); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - if (format != null) { - builder.field(DerivativeParser.FORMAT.getPreferredName(), format); - } - if (gapPolicy != null) { - builder.field(DerivativeParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); - } - if (units != null) { - builder.field(DerivativeParser.UNIT.getPreferredName(), units); - } - return builder; - } - - @Override - protected boolean doEquals(Object obj) { - DerivativePipelineAggregatorBuilder other = (DerivativePipelineAggregatorBuilder) obj; - if (!Objects.equals(format, other.format)) { - return false; - } - if (!Objects.equals(gapPolicy, other.gapPolicy)) { - return false; - } - if (!Objects.equals(units, other.units)) { - return false; - } - return true; - } - - @Override - protected int doHashCode() { - return Objects.hash(format, gapPolicy, units); - } - - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java new file mode 100644 index 00000000000..dd7de1e19c3 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java @@ -0,0 +1,200 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.derivative; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.rounding.DateTimeUnit; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregatorFactory; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; +import org.elasticsearch.search.aggregations.support.format.ValueFormat; +import org.elasticsearch.search.aggregations.support.format.ValueFormatter; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuilder { + + static final DerivativePipelineAggregatorBuilder PROTOTYPE = new DerivativePipelineAggregatorBuilder("", ""); + + private String format; + private GapPolicy gapPolicy = GapPolicy.SKIP; + private String units; + + public DerivativePipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private DerivativePipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, DerivativePipelineAggregator.TYPE.name(), bucketsPaths); + } + + public DerivativePipelineAggregatorBuilder format(String format) { + if (format == null) { + throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); + } + this.format = format; + return this; + } + + public String format() { + return format; + } + + public DerivativePipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + if (gapPolicy == null) { + throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); + } + this.gapPolicy = gapPolicy; + return this; + } + + public GapPolicy gapPolicy() { + return gapPolicy; + } + + public DerivativePipelineAggregatorBuilder unit(String units) { + if (units == null) { + throw new IllegalArgumentException("[units] must not be null: [" + name + "]"); + } + this.units = units; + return this; + } + + public DerivativePipelineAggregatorBuilder unit(DateHistogramInterval units) { + if (units == null) { + throw new IllegalArgumentException("[units] must not be null: [" + name + "]"); + } + this.units = units.toString(); + return this; + } + + public String unit() { + return units; + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + ValueFormatter formatter; + if (format != null) { + formatter = ValueFormat.Patternable.Number.format(format).formatter(); + } else { + formatter = ValueFormatter.RAW; + } + Long xAxisUnits = null; + if (units != null) { + DateTimeUnit dateTimeUnit = DateHistogramAggregatorFactory.DATE_FIELD_UNITS.get(units); + if (dateTimeUnit != null) { + xAxisUnits = dateTimeUnit.field().getDurationField().getUnitMillis(); + } else { + TimeValue timeValue = TimeValue.parseTimeValue(units, null, getClass().getSimpleName() + ".unit"); + if (timeValue != null) { + xAxisUnits = timeValue.getMillis(); + } + } + } + return new DerivativePipelineAggregator(name, bucketsPaths, formatter, gapPolicy, xAxisUnits, metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatoractories) { + if (bucketsPaths.length != 1) { + throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + if (!(parent instanceof AbstractHistogramAggregatorFactory)) { + throw new IllegalStateException("derivative aggregation [" + name + + "] must have a histogram or date_histogram as parent"); + } else { + AbstractHistogramAggregatorFactory histoParent = (AbstractHistogramAggregatorFactory) parent; + if (histoParent.minDocCount() != 0) { + throw new IllegalStateException("parent histogram of derivative aggregation [" + name + + "] must have min_doc_count of 0"); + } + } + } + + @Override + protected DerivativePipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { + DerivativePipelineAggregatorBuilder factory = new DerivativePipelineAggregatorBuilder(name, bucketsPaths); + factory.format = in.readOptionalString(); + if (in.readBoolean()) { + factory.gapPolicy = GapPolicy.readFrom(in); + } + factory.units = in.readOptionalString(); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeOptionalString(format); + boolean hasGapPolicy = gapPolicy != null; + out.writeBoolean(hasGapPolicy); + if (hasGapPolicy) { + gapPolicy.writeTo(out); + } + out.writeOptionalString(units); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + if (format != null) { + builder.field(DerivativeParser.FORMAT.getPreferredName(), format); + } + if (gapPolicy != null) { + builder.field(DerivativeParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); + } + if (units != null) { + builder.field(DerivativeParser.UNIT.getPreferredName(), units); + } + return builder; + } + + @Override + protected boolean doEquals(Object obj) { + DerivativePipelineAggregatorBuilder other = (DerivativePipelineAggregatorBuilder) obj; + if (!Objects.equals(format, other.format)) { + return false; + } + if (!Objects.equals(gapPolicy, other.gapPolicy)) { + return false; + } + if (!Objects.equals(units, other.units)) { + return false; + } + return true; + } + + @Override + protected int doHashCode() { + return Objects.hash(format, gapPolicy, units); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java index f03355c5c8e..96a7dacb0f3 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java @@ -56,7 +56,7 @@ public class MovAvgParser implements PipelineAggregator.Parser { } @Override - public MovAvgPipelineAggregator.MovAvgPipelineAggregatorBuilder parse(String pipelineAggregatorName, XContentParser parser, + public MovAvgPipelineAggregatorBuilder parse(String pipelineAggregatorName, XContentParser parser, QueryParseContext context) throws IOException { XContentParser.Token token; String currentFieldName = null; @@ -140,8 +140,8 @@ public class MovAvgParser implements PipelineAggregator.Parser { + "] for movingAvg aggregation [" + pipelineAggregatorName + "]"); } - MovAvgPipelineAggregator.MovAvgPipelineAggregatorBuilder factory = - new MovAvgPipelineAggregator.MovAvgPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); + MovAvgPipelineAggregatorBuilder factory = + new MovAvgPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); if (format != null) { factory.format(format); } @@ -176,8 +176,8 @@ public class MovAvgParser implements PipelineAggregator.Parser { } @Override - public MovAvgPipelineAggregator.MovAvgPipelineAggregatorBuilder getFactoryPrototype() { - return MovAvgPipelineAggregator.MovAvgPipelineAggregatorBuilder.PROTOTYPE; + public MovAvgPipelineAggregatorBuilder getFactoryPrototype() { + return MovAvgPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregator.java index d64ca97b925..d5d9d040d73 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregator.java @@ -22,25 +22,18 @@ package org.elasticsearch.search.aggregations.pipeline.movavg; import org.elasticsearch.common.collect.EvictingQueue; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregationExecutionException; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregations; -import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel; -import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelBuilder; import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelStreams; -import org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel; -import org.elasticsearch.search.aggregations.support.format.ValueFormat; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatterStreams; import org.joda.time.DateTime; @@ -50,7 +43,6 @@ import java.util.ArrayList; import java.util.List; import java.util.ListIterator; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -278,266 +270,4 @@ public class MovAvgPipelineAggregator extends PipelineAggregator { out.writeBoolean(minimize); } - - public static class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder { - - static final MovAvgPipelineAggregatorBuilder PROTOTYPE = new MovAvgPipelineAggregatorBuilder("", ""); - - private String format; - private GapPolicy gapPolicy = GapPolicy.SKIP; - private int window = 5; - private MovAvgModel model = new SimpleModel(); - private int predict = 0; - private Boolean minimize; - - public MovAvgPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private MovAvgPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - /** - * Sets the format to use on the output of this aggregation. - */ - public MovAvgPipelineAggregatorBuilder format(String format) { - if (format == null) { - throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); - } - this.format = format; - return this; - } - - /** - * Gets the format to use on the output of this aggregation. - */ - public String format() { - return format; - } - - /** - * Sets the GapPolicy to use on the output of this aggregation. - */ - public MovAvgPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { - if (gapPolicy == null) { - throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); - } - this.gapPolicy = gapPolicy; - return this; - } - - /** - * Gets the GapPolicy to use on the output of this aggregation. - */ - public GapPolicy gapPolicy() { - return gapPolicy; - } - - protected ValueFormatter formatter() { - if (format != null) { - return ValueFormat.Patternable.Number.format(format).formatter(); - } else { - return ValueFormatter.RAW; - } - } - - /** - * Sets the window size for the moving average. This window will "slide" - * across the series, and the values inside that window will be used to - * calculate the moving avg value - * - * @param window - * Size of window - */ - public MovAvgPipelineAggregatorBuilder window(int window) { - if (window <= 0) { - throw new IllegalArgumentException("[window] must be a positive integer: [" + name + "]"); - } - this.window = window; - return this; - } - - /** - * Gets the window size for the moving average. This window will "slide" - * across the series, and the values inside that window will be used to - * calculate the moving avg value - */ - public int window() { - return window; - } - - /** - * Sets a MovAvgModel for the Moving Average. The model is used to - * define what type of moving average you want to use on the series - * - * @param model - * A MovAvgModel which has been prepopulated with settings - */ - public MovAvgPipelineAggregatorBuilder modelBuilder(MovAvgModelBuilder model) { - if (model == null) { - throw new IllegalArgumentException("[model] must not be null: [" + name + "]"); - } - this.model = model.build(); - return this; - } - - /** - * Sets a MovAvgModel for the Moving Average. The model is used to - * define what type of moving average you want to use on the series - * - * @param model - * A MovAvgModel which has been prepopulated with settings - */ - public MovAvgPipelineAggregatorBuilder model(MovAvgModel model) { - if (model == null) { - throw new IllegalArgumentException("[model] must not be null: [" + name + "]"); - } - this.model = model; - return this; - } - - /** - * Gets a MovAvgModel for the Moving Average. The model is used to - * define what type of moving average you want to use on the series - */ - public MovAvgModel model() { - return model; - } - - /** - * Sets the number of predictions that should be returned. Each - * prediction will be spaced at the intervals specified in the - * histogram. E.g "predict: 2" will return two new buckets at the end of - * the histogram with the predicted values. - * - * @param predict - * Number of predictions to make - */ - public MovAvgPipelineAggregatorBuilder predict(int predict) { - if (predict <= 0) { - throw new IllegalArgumentException("predict must be greater than 0. Found [" + predict + "] in [" + name + "]"); - } - this.predict = predict; - return this; - } - - /** - * Gets the number of predictions that should be returned. Each - * prediction will be spaced at the intervals specified in the - * histogram. E.g "predict: 2" will return two new buckets at the end of - * the histogram with the predicted values. - */ - public int predict() { - return predict; - } - - /** - * Sets whether the model should be fit to the data using a cost - * minimizing algorithm. - * - * @param minimize - * If the model should be fit to the underlying data - */ - public MovAvgPipelineAggregatorBuilder minimize(boolean minimize) { - this.minimize = minimize; - return this; - } - - /** - * Gets whether the model should be fit to the data using a cost - * minimizing algorithm. - */ - public Boolean minimize() { - return minimize; - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - // If the user doesn't set a preference for cost minimization, ask - // what the model prefers - boolean minimize = this.minimize == null ? model.minimizeByDefault() : this.minimize; - return new MovAvgPipelineAggregator(name, bucketsPaths, formatter(), gapPolicy, window, predict, model, minimize, metaData); - } - - @Override - public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, - List> pipelineAggregatoractories) { - if (minimize != null && minimize && !model.canBeMinimized()) { - // If the user asks to minimize, but this model doesn't support - // it, throw exception - throw new IllegalStateException("The [" + model + "] model cannot be minimized for aggregation [" + name + "]"); - } - if (bucketsPaths.length != 1) { - throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() - + " must contain a single entry for aggregation [" + name + "]"); - } - if (!(parent instanceof AbstractHistogramAggregatorFactory)) { - throw new IllegalStateException("moving average aggregation [" + name - + "] must have a histogram or date_histogram as parent"); - } else { - AbstractHistogramAggregatorFactory histoParent = (AbstractHistogramAggregatorFactory) parent; - if (histoParent.minDocCount() != 0) { - throw new IllegalStateException("parent histogram of moving average aggregation [" + name - + "] must have min_doc_count of 0"); - } - } - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - if (format != null) { - builder.field(MovAvgParser.FORMAT.getPreferredName(), format); - } - builder.field(MovAvgParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); - model.toXContent(builder, params); - builder.field(MovAvgParser.WINDOW.getPreferredName(), window); - if (predict > 0) { - builder.field(MovAvgParser.PREDICT.getPreferredName(), predict); - } - if (minimize != null) { - builder.field(MovAvgParser.MINIMIZE.getPreferredName(), minimize); - } - return builder; - } - - @Override - protected MovAvgPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { - MovAvgPipelineAggregatorBuilder factory = new MovAvgPipelineAggregatorBuilder(name, bucketsPaths); - factory.format = in.readOptionalString(); - factory.gapPolicy = GapPolicy.readFrom(in); - factory.window = in.readVInt(); - factory.model = MovAvgModelStreams.read(in); - factory.predict = in.readVInt(); - factory.minimize = in.readOptionalBoolean(); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeOptionalString(format); - gapPolicy.writeTo(out); - out.writeVInt(window); - model.writeTo(out); - out.writeVInt(predict); - out.writeOptionalBoolean(minimize); - } - - @Override - protected int doHashCode() { - return Objects.hash(format, gapPolicy, window, model, predict, minimize); - } - - @Override - protected boolean doEquals(Object obj) { - MovAvgPipelineAggregatorBuilder other = (MovAvgPipelineAggregatorBuilder) obj; - return Objects.equals(format, other.format) - && Objects.equals(gapPolicy, other.gapPolicy) - && Objects.equals(window, other.window) - && Objects.equals(model, other.model) - && Objects.equals(predict, other.predict) - && Objects.equals(minimize, other.minimize); - } - - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..8f6d116c5f1 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java @@ -0,0 +1,302 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.movavg; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.AggregatorFactory; +import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; +import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel; +import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelStreams; +import org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel; +import org.elasticsearch.search.aggregations.support.format.ValueFormat; +import org.elasticsearch.search.aggregations.support.format.ValueFormatter; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder { + + static final MovAvgPipelineAggregatorBuilder PROTOTYPE = new MovAvgPipelineAggregatorBuilder("", ""); + + private String format; + private GapPolicy gapPolicy = GapPolicy.SKIP; + private int window = 5; + private MovAvgModel model = new SimpleModel(); + private int predict = 0; + private Boolean minimize; + + public MovAvgPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private MovAvgPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, MovAvgPipelineAggregator.TYPE.name(), bucketsPaths); + } + + /** + * Sets the format to use on the output of this aggregation. + */ + public MovAvgPipelineAggregatorBuilder format(String format) { + if (format == null) { + throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); + } + this.format = format; + return this; + } + + /** + * Gets the format to use on the output of this aggregation. + */ + public String format() { + return format; + } + + /** + * Sets the GapPolicy to use on the output of this aggregation. + */ + public MovAvgPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + if (gapPolicy == null) { + throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); + } + this.gapPolicy = gapPolicy; + return this; + } + + /** + * Gets the GapPolicy to use on the output of this aggregation. + */ + public GapPolicy gapPolicy() { + return gapPolicy; + } + + protected ValueFormatter formatter() { + if (format != null) { + return ValueFormat.Patternable.Number.format(format).formatter(); + } else { + return ValueFormatter.RAW; + } + } + + /** + * Sets the window size for the moving average. This window will "slide" + * across the series, and the values inside that window will be used to + * calculate the moving avg value + * + * @param window + * Size of window + */ + public MovAvgPipelineAggregatorBuilder window(int window) { + if (window <= 0) { + throw new IllegalArgumentException("[window] must be a positive integer: [" + name + "]"); + } + this.window = window; + return this; + } + + /** + * Gets the window size for the moving average. This window will "slide" + * across the series, and the values inside that window will be used to + * calculate the moving avg value + */ + public int window() { + return window; + } + + /** + * Sets a MovAvgModel for the Moving Average. The model is used to + * define what type of moving average you want to use on the series + * + * @param model + * A MovAvgModel which has been prepopulated with settings + */ + public MovAvgPipelineAggregatorBuilder modelBuilder(MovAvgModelBuilder model) { + if (model == null) { + throw new IllegalArgumentException("[model] must not be null: [" + name + "]"); + } + this.model = model.build(); + return this; + } + + /** + * Sets a MovAvgModel for the Moving Average. The model is used to + * define what type of moving average you want to use on the series + * + * @param model + * A MovAvgModel which has been prepopulated with settings + */ + public MovAvgPipelineAggregatorBuilder model(MovAvgModel model) { + if (model == null) { + throw new IllegalArgumentException("[model] must not be null: [" + name + "]"); + } + this.model = model; + return this; + } + + /** + * Gets a MovAvgModel for the Moving Average. The model is used to + * define what type of moving average you want to use on the series + */ + public MovAvgModel model() { + return model; + } + + /** + * Sets the number of predictions that should be returned. Each + * prediction will be spaced at the intervals specified in the + * histogram. E.g "predict: 2" will return two new buckets at the end of + * the histogram with the predicted values. + * + * @param predict + * Number of predictions to make + */ + public MovAvgPipelineAggregatorBuilder predict(int predict) { + if (predict <= 0) { + throw new IllegalArgumentException("predict must be greater than 0. Found [" + predict + "] in [" + name + "]"); + } + this.predict = predict; + return this; + } + + /** + * Gets the number of predictions that should be returned. Each + * prediction will be spaced at the intervals specified in the + * histogram. E.g "predict: 2" will return two new buckets at the end of + * the histogram with the predicted values. + */ + public int predict() { + return predict; + } + + /** + * Sets whether the model should be fit to the data using a cost + * minimizing algorithm. + * + * @param minimize + * If the model should be fit to the underlying data + */ + public MovAvgPipelineAggregatorBuilder minimize(boolean minimize) { + this.minimize = minimize; + return this; + } + + /** + * Gets whether the model should be fit to the data using a cost + * minimizing algorithm. + */ + public Boolean minimize() { + return minimize; + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + // If the user doesn't set a preference for cost minimization, ask + // what the model prefers + boolean minimize = this.minimize == null ? model.minimizeByDefault() : this.minimize; + return new MovAvgPipelineAggregator(name, bucketsPaths, formatter(), gapPolicy, window, predict, model, minimize, metaData); + } + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List> pipelineAggregatoractories) { + if (minimize != null && minimize && !model.canBeMinimized()) { + // If the user asks to minimize, but this model doesn't support + // it, throw exception + throw new IllegalStateException("The [" + model + "] model cannot be minimized for aggregation [" + name + "]"); + } + if (bucketsPaths.length != 1) { + throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + + " must contain a single entry for aggregation [" + name + "]"); + } + if (!(parent instanceof AbstractHistogramAggregatorFactory)) { + throw new IllegalStateException("moving average aggregation [" + name + + "] must have a histogram or date_histogram as parent"); + } else { + AbstractHistogramAggregatorFactory histoParent = (AbstractHistogramAggregatorFactory) parent; + if (histoParent.minDocCount() != 0) { + throw new IllegalStateException("parent histogram of moving average aggregation [" + name + + "] must have min_doc_count of 0"); + } + } + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + if (format != null) { + builder.field(MovAvgParser.FORMAT.getPreferredName(), format); + } + builder.field(MovAvgParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); + model.toXContent(builder, params); + builder.field(MovAvgParser.WINDOW.getPreferredName(), window); + if (predict > 0) { + builder.field(MovAvgParser.PREDICT.getPreferredName(), predict); + } + if (minimize != null) { + builder.field(MovAvgParser.MINIMIZE.getPreferredName(), minimize); + } + return builder; + } + + @Override + protected MovAvgPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { + MovAvgPipelineAggregatorBuilder factory = new MovAvgPipelineAggregatorBuilder(name, bucketsPaths); + factory.format = in.readOptionalString(); + factory.gapPolicy = GapPolicy.readFrom(in); + factory.window = in.readVInt(); + factory.model = MovAvgModelStreams.read(in); + factory.predict = in.readVInt(); + factory.minimize = in.readOptionalBoolean(); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeOptionalString(format); + gapPolicy.writeTo(out); + out.writeVInt(window); + model.writeTo(out); + out.writeVInt(predict); + out.writeOptionalBoolean(minimize); + } + + @Override + protected int doHashCode() { + return Objects.hash(format, gapPolicy, window, model, predict, minimize); + } + + @Override + protected boolean doEquals(Object obj) { + MovAvgPipelineAggregatorBuilder other = (MovAvgPipelineAggregatorBuilder) obj; + return Objects.equals(format, other.format) + && Objects.equals(gapPolicy, other.gapPolicy) + && Objects.equals(window, other.window) + && Objects.equals(model, other.model) + && Objects.equals(predict, other.predict) + && Objects.equals(minimize, other.minimize); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java index 3a0dca088d4..2fb02bbc550 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java @@ -41,7 +41,7 @@ public class SerialDiffParser implements PipelineAggregator.Parser { } @Override - public SerialDiffPipelineAggregator.SerialDiffPipelineAggregatorBuilder parse(String reducerName, XContentParser parser, + public SerialDiffPipelineAggregatorBuilder parse(String reducerName, XContentParser parser, QueryParseContext context) throws IOException { XContentParser.Token token; String currentFieldName = null; @@ -100,8 +100,8 @@ public class SerialDiffParser implements PipelineAggregator.Parser { "Missing required field [" + BUCKETS_PATH.getPreferredName() + "] for derivative aggregation [" + reducerName + "]"); } - SerialDiffPipelineAggregator.SerialDiffPipelineAggregatorBuilder factory = - new SerialDiffPipelineAggregator.SerialDiffPipelineAggregatorBuilder(reducerName, bucketsPaths[0]); + SerialDiffPipelineAggregatorBuilder factory = + new SerialDiffPipelineAggregatorBuilder(reducerName, bucketsPaths[0]); if (lag != null) { factory.lag(lag); } @@ -115,8 +115,8 @@ public class SerialDiffParser implements PipelineAggregator.Parser { } @Override - public SerialDiffPipelineAggregator.SerialDiffPipelineAggregatorBuilder getFactoryPrototype() { - return SerialDiffPipelineAggregator.SerialDiffPipelineAggregatorBuilder.PROTOTYPE; + public SerialDiffPipelineAggregatorBuilder getFactoryPrototype() { + return SerialDiffPipelineAggregatorBuilder.PROTOTYPE; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregator.java index b737ec1d2c8..44f72c3320d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregator.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.EvictingQueue; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext; import org.elasticsearch.search.aggregations.InternalAggregation.Type; @@ -32,9 +31,7 @@ import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; -import org.elasticsearch.search.aggregations.support.format.ValueFormat; import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatterStreams; @@ -42,7 +39,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -144,127 +140,4 @@ public class SerialDiffPipelineAggregator extends PipelineAggregator { gapPolicy.writeTo(out); out.writeVInt(lag); } - - public static class SerialDiffPipelineAggregatorBuilder extends PipelineAggregatorBuilder { - - static final SerialDiffPipelineAggregatorBuilder PROTOTYPE = new SerialDiffPipelineAggregatorBuilder("", ""); - - private String format; - private GapPolicy gapPolicy = GapPolicy.SKIP; - private int lag = 1; - - public SerialDiffPipelineAggregatorBuilder(String name, String bucketsPath) { - this(name, new String[] { bucketsPath }); - } - - private SerialDiffPipelineAggregatorBuilder(String name, String[] bucketsPaths) { - super(name, TYPE.name(), bucketsPaths); - } - - /** - * Sets the lag to use when calculating the serial difference. - */ - public SerialDiffPipelineAggregatorBuilder lag(int lag) { - if (lag <= 0) { - throw new IllegalArgumentException("[lag] must be a positive integer: [" + name + "]"); - } - this.lag = lag; - return this; - } - - /** - * Gets the lag to use when calculating the serial difference. - */ - public int lag() { - return lag; - } - - /** - * Sets the format to use on the output of this aggregation. - */ - public SerialDiffPipelineAggregatorBuilder format(String format) { - if (format == null) { - throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); - } - this.format = format; - return this; - } - - /** - * Gets the format to use on the output of this aggregation. - */ - public String format() { - return format; - } - - /** - * Sets the GapPolicy to use on the output of this aggregation. - */ - public SerialDiffPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { - if (gapPolicy == null) { - throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); - } - this.gapPolicy = gapPolicy; - return this; - } - - /** - * Gets the GapPolicy to use on the output of this aggregation. - */ - public GapPolicy gapPolicy() { - return gapPolicy; - } - - protected ValueFormatter formatter() { - if (format != null) { - return ValueFormat.Patternable.Number.format(format).formatter(); - } else { - return ValueFormatter.RAW; - } - } - - @Override - protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new SerialDiffPipelineAggregator(name, bucketsPaths, formatter(), gapPolicy, lag, metaData); - } - - @Override - protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { - if (format != null) { - builder.field(SerialDiffParser.FORMAT.getPreferredName(), format); - } - builder.field(SerialDiffParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); - builder.field(SerialDiffParser.LAG.getPreferredName(), lag); - return builder; - } - - @Override - protected SerialDiffPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { - SerialDiffPipelineAggregatorBuilder factory = new SerialDiffPipelineAggregatorBuilder(name, bucketsPaths); - factory.format = in.readOptionalString(); - factory.gapPolicy = GapPolicy.readFrom(in); - factory.lag = in.readVInt(); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeOptionalString(format); - gapPolicy.writeTo(out); - out.writeVInt(lag); - } - - @Override - protected int doHashCode() { - return Objects.hash(format, gapPolicy, lag); - } - @Override - protected boolean doEquals(Object obj) { - SerialDiffPipelineAggregatorBuilder other = (SerialDiffPipelineAggregatorBuilder) obj; - return Objects.equals(format, other.format) - && Objects.equals(gapPolicy, other.gapPolicy) - && Objects.equals(lag, other.lag); - } - - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java new file mode 100644 index 00000000000..ad7b83442e2 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java @@ -0,0 +1,156 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.search.aggregations.pipeline.serialdiff; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; +import org.elasticsearch.search.aggregations.support.format.ValueFormat; +import org.elasticsearch.search.aggregations.support.format.ValueFormatter; + +import java.io.IOException; +import java.util.Map; +import java.util.Objects; + +public class SerialDiffPipelineAggregatorBuilder extends PipelineAggregatorBuilder { + + static final SerialDiffPipelineAggregatorBuilder PROTOTYPE = new SerialDiffPipelineAggregatorBuilder("", ""); + + private String format; + private GapPolicy gapPolicy = GapPolicy.SKIP; + private int lag = 1; + + public SerialDiffPipelineAggregatorBuilder(String name, String bucketsPath) { + this(name, new String[] { bucketsPath }); + } + + private SerialDiffPipelineAggregatorBuilder(String name, String[] bucketsPaths) { + super(name, SerialDiffPipelineAggregator.TYPE.name(), bucketsPaths); + } + + /** + * Sets the lag to use when calculating the serial difference. + */ + public SerialDiffPipelineAggregatorBuilder lag(int lag) { + if (lag <= 0) { + throw new IllegalArgumentException("[lag] must be a positive integer: [" + name + "]"); + } + this.lag = lag; + return this; + } + + /** + * Gets the lag to use when calculating the serial difference. + */ + public int lag() { + return lag; + } + + /** + * Sets the format to use on the output of this aggregation. + */ + public SerialDiffPipelineAggregatorBuilder format(String format) { + if (format == null) { + throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); + } + this.format = format; + return this; + } + + /** + * Gets the format to use on the output of this aggregation. + */ + public String format() { + return format; + } + + /** + * Sets the GapPolicy to use on the output of this aggregation. + */ + public SerialDiffPipelineAggregatorBuilder gapPolicy(GapPolicy gapPolicy) { + if (gapPolicy == null) { + throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]"); + } + this.gapPolicy = gapPolicy; + return this; + } + + /** + * Gets the GapPolicy to use on the output of this aggregation. + */ + public GapPolicy gapPolicy() { + return gapPolicy; + } + + protected ValueFormatter formatter() { + if (format != null) { + return ValueFormat.Patternable.Number.format(format).formatter(); + } else { + return ValueFormatter.RAW; + } + } + + @Override + protected PipelineAggregator createInternal(Map metaData) throws IOException { + return new SerialDiffPipelineAggregator(name, bucketsPaths, formatter(), gapPolicy, lag, metaData); + } + + @Override + protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { + if (format != null) { + builder.field(SerialDiffParser.FORMAT.getPreferredName(), format); + } + builder.field(SerialDiffParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); + builder.field(SerialDiffParser.LAG.getPreferredName(), lag); + return builder; + } + + @Override + protected SerialDiffPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { + SerialDiffPipelineAggregatorBuilder factory = new SerialDiffPipelineAggregatorBuilder(name, bucketsPaths); + factory.format = in.readOptionalString(); + factory.gapPolicy = GapPolicy.readFrom(in); + factory.lag = in.readVInt(); + return factory; + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeOptionalString(format); + gapPolicy.writeTo(out); + out.writeVInt(lag); + } + + @Override + protected int doHashCode() { + return Objects.hash(format, gapPolicy, lag); + } + @Override + protected boolean doEquals(Object obj) { + SerialDiffPipelineAggregatorBuilder other = (SerialDiffPipelineAggregatorBuilder) obj; + return Objects.equals(format, other.format) + && Objects.equals(gapPolicy, other.gapPolicy) + && Objects.equals(lag, other.lag); + } + +} \ No newline at end of file diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenTests.java index 3e0941e2121..3f8684c36db 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenTests.java @@ -20,10 +20,9 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.children.ParentToChildrenAggregator; -import org.elasticsearch.search.aggregations.bucket.children.ParentToChildrenAggregator.ChildrenAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregatorBuilder; -public class ChildrenTests extends BaseAggregationTestCase { +public class ChildrenTests extends BaseAggregationTestCase { @Override protected ChildrenAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramTests.java index 0f2411f791d..58641a43b68 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramTests.java @@ -20,10 +20,10 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.search.aggregations.bucket.histogram.ExtendedBounds; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Order; -import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator.DateHistogramAggregatorBuilder; public class DateHistogramTests extends BaseAggregationTestCase { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DiversifiedSamplerIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DiversifiedSamplerIT.java index 1b72944d028..1c53c354b0d 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DiversifiedSamplerIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DiversifiedSamplerIT.java @@ -22,9 +22,9 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.index.query.TermQueryBuilder; +import org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.sampler.Sampler; import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregator; -import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregator.DiversifiedAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorBuilder; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DiversifiedSamplerTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DiversifiedSamplerTests.java index a900496f942..512d7a8d69b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DiversifiedSamplerTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DiversifiedSamplerTests.java @@ -21,14 +21,14 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.script.Script; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregator; +import org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregator.ExecutionMode; -public class DiversifiedSamplerTests extends BaseAggregationTestCase { +public class DiversifiedSamplerTests extends BaseAggregationTestCase { @Override - protected final SamplerAggregator.DiversifiedAggregatorBuilder createTestAggregatorBuilder() { - SamplerAggregator.DiversifiedAggregatorBuilder factory = new SamplerAggregator.DiversifiedAggregatorBuilder("foo"); + protected final DiversifiedAggregatorBuilder createTestAggregatorBuilder() { + DiversifiedAggregatorBuilder factory = new DiversifiedAggregatorBuilder("foo"); String field = randomNumericField(); int randomFieldBranch = randomInt(3); switch (randomFieldBranch) { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceRangeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceRangeTests.java index 39eccf41c6f..b1fa01c5f19 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceRangeTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoDistanceRangeTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceParser.GeoDistanceAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceParser.Range; import org.elasticsearch.test.geo.RandomShapeGenerator; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoHashGridTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoHashGridTests.java index 935d03b96f6..34e3e266d6a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoHashGridTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GeoHashGridTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridParser.GeoGridAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregatorBuilder; public class GeoHashGridTests extends BaseAggregationTestCase { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GlobalTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GlobalTests.java index c5dd307cc7a..ca2b5c9d6c0 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GlobalTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/GlobalTests.java @@ -20,14 +20,13 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator; -import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator.GlobalAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregatorBuilder; -public class GlobalTests extends BaseAggregationTestCase { +public class GlobalTests extends BaseAggregationTestCase { @Override protected GlobalAggregatorBuilder createTestAggregatorBuilder() { - return new GlobalAggregator.GlobalAggregatorBuilder(randomAsciiOfLengthBetween(3, 20)); + return new GlobalAggregatorBuilder(randomAsciiOfLengthBetween(3, 20)); } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramTests.java index dbb54cec43b..1cd930ecc31 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramTests.java @@ -22,10 +22,9 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; import org.elasticsearch.search.aggregations.bucket.histogram.ExtendedBounds; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Order; -import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator; -import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregator.HistogramAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregatorBuilder; -public class HistogramTests extends BaseAggregationTestCase { +public class HistogramTests extends BaseAggregationTestCase { @Override protected HistogramAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/NaNSortingIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/NaNSortingIT.java index d303a2eff2e..7b055a3de5f 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/NaNSortingIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/NaNSortingIT.java @@ -27,9 +27,9 @@ import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.metrics.avg.Avg; -import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregator; +import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; -import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregator; +import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.test.ESIntegTestCase; @@ -48,8 +48,8 @@ public class NaNSortingIT extends ESIntegTestCase { private enum SubAggregation { AVG("avg") { @Override - public AvgAggregator.AvgAggregatorBuilder builder() { - AvgAggregator.AvgAggregatorBuilder factory = avg(name); + public AvgAggregatorBuilder builder() { + AvgAggregatorBuilder factory = avg(name); factory.field("numeric_field"); return factory; } @@ -60,8 +60,8 @@ public class NaNSortingIT extends ESIntegTestCase { }, VARIANCE("variance") { @Override - public ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder builder() { - ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder factory = extendedStats(name); + public ExtendedStatsAggregatorBuilder builder() { + ExtendedStatsAggregatorBuilder factory = extendedStats(name); factory.field("numeric_field"); return factory; } @@ -76,8 +76,8 @@ public class NaNSortingIT extends ESIntegTestCase { }, STD_DEVIATION("std_deviation"){ @Override - public ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder builder() { - ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder factory = extendedStats(name); + public ExtendedStatsAggregatorBuilder builder() { + ExtendedStatsAggregatorBuilder factory = extendedStats(name); factory.field("numeric_field"); return factory; } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeTests.java index 159f4914373..b9c60dab1be 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeTests.java @@ -20,11 +20,10 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator; -import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.RangeAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range; +import org.elasticsearch.search.aggregations.bucket.range.RangeAggregatorBuilder; -public class RangeTests extends BaseAggregationTestCase { +public class RangeTests extends BaseAggregationTestCase { @Override protected RangeAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SamplerIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SamplerIT.java index 4795e1385d1..f42d213bb57 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SamplerIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SamplerIT.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.search.SearchType; import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.search.aggregations.bucket.sampler.Sampler; import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregator; +import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; import org.elasticsearch.search.aggregations.metrics.max.Max; @@ -38,8 +39,6 @@ import static org.elasticsearch.search.aggregations.AggregationBuilders.sampler; import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; -import static org.elasticsearch.search.aggregations.AggregationBuilders.sampler; -import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -124,7 +123,7 @@ public class SamplerIT extends ESIntegTestCase { } public void testSimpleSampler() throws Exception { - SamplerAggregator.SamplerAggregatorBuilder sampleAgg = sampler("sample").shardSize(100); + SamplerAggregatorBuilder sampleAgg = sampler("sample").shardSize(100); sampleAgg.subAggregation(terms("authors").field("author")); SearchResponse response = client().prepareSearch("test").setSearchType(SearchType.QUERY_AND_FETCH) .setQuery(new TermQueryBuilder("genre", "fantasy")).setFrom(0).setSize(60).addAggregation(sampleAgg).execute().actionGet(); @@ -141,7 +140,7 @@ public class SamplerIT extends ESIntegTestCase { } public void testUnmappedChildAggNoDiversity() throws Exception { - SamplerAggregator.SamplerAggregatorBuilder sampleAgg = sampler("sample").shardSize(100); + SamplerAggregatorBuilder sampleAgg = sampler("sample").shardSize(100); sampleAgg.subAggregation(terms("authors").field("author")); SearchResponse response = client().prepareSearch("idx_unmapped") .setSearchType(SearchType.QUERY_AND_FETCH) @@ -158,7 +157,7 @@ public class SamplerIT extends ESIntegTestCase { } public void testPartiallyUnmappedChildAggNoDiversity() throws Exception { - SamplerAggregator.SamplerAggregatorBuilder sampleAgg = sampler("sample").shardSize(100); + SamplerAggregatorBuilder sampleAgg = sampler("sample").shardSize(100); sampleAgg.subAggregation(terms("authors").field("author")); SearchResponse response = client().prepareSearch("idx_unmapped", "test") .setSearchType(SearchType.QUERY_AND_FETCH) diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SamplerTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SamplerTests.java index dfa20604c2c..8d792fd72ff 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SamplerTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SamplerTests.java @@ -20,13 +20,13 @@ package org.elasticsearch.search.aggregations.bucket; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregator; +import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregatorBuilder; -public class SamplerTests extends BaseAggregationTestCase { +public class SamplerTests extends BaseAggregationTestCase { @Override - protected final SamplerAggregator.SamplerAggregatorBuilder createTestAggregatorBuilder() { - SamplerAggregator.SamplerAggregatorBuilder factory = new SamplerAggregator.SamplerAggregatorBuilder("foo"); + protected final SamplerAggregatorBuilder createTestAggregatorBuilder() { + SamplerAggregatorBuilder factory = new SamplerAggregatorBuilder("foo"); if (randomBoolean()) { factory.shardSize(randomIntBetween(1, 1000)); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorTests.java index cfe7e0079f6..dbe10e2ff9d 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorTests.java @@ -123,7 +123,7 @@ public class NestedAggregatorTests extends ESSingleNodeTestCase { AggregationContext context = new AggregationContext(searchContext); AggregatorFactories.Builder builder = AggregatorFactories.builder(); - NestedAggregator.NestedAggregatorBuilder factory = new NestedAggregator.NestedAggregatorBuilder("test", "nested_field"); + NestedAggregatorBuilder factory = new NestedAggregatorBuilder("test", "nested_field"); builder.addAggregator(factory); AggregatorFactories factories = builder.build(context, null); searchContext.aggregations(new SearchContextAggregations(factories)); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedTests.java index 5aa26cd7e52..6ea5b3791d8 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedTests.java @@ -20,9 +20,8 @@ package org.elasticsearch.search.aggregations.bucket.nested; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregator.NestedAggregatorBuilder; -public class NestedTests extends BaseAggregationTestCase { +public class NestedTests extends BaseAggregationTestCase { @Override protected NestedAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedTests.java index 56eb4120252..1a45c550bc1 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedTests.java @@ -20,9 +20,8 @@ package org.elasticsearch.search.aggregations.bucket.nested; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregator.ReverseNestedAggregatorBuilder; -public class ReverseNestedTests extends BaseAggregationTestCase { +public class ReverseNestedTests extends BaseAggregationTestCase { @Override protected ReverseNestedAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgTests.java index df1b78cd2a1..61e685169f6 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgTests.java @@ -19,13 +19,13 @@ package org.elasticsearch.search.aggregations.metrics; -import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregator; +import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregatorBuilder; -public class AvgTests extends AbstractNumericMetricTestCase { +public class AvgTests extends AbstractNumericMetricTestCase { @Override - protected AvgAggregator.AvgAggregatorBuilder doCreateTestAggregatorFactory() { - return new AvgAggregator.AvgAggregatorBuilder("foo"); + protected AvgAggregatorBuilder doCreateTestAggregatorFactory() { + return new AvgAggregatorBuilder("foo"); } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsTests.java index 7a9e30bc581..4a7ca7e8b38 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsTests.java @@ -19,13 +19,13 @@ package org.elasticsearch.search.aggregations.metrics; -import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregator; +import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregatorBuilder; -public class ExtendedStatsTests extends AbstractNumericMetricTestCase { +public class ExtendedStatsTests extends AbstractNumericMetricTestCase { @Override - protected ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder doCreateTestAggregatorFactory() { - ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder factory = new ExtendedStatsAggregator.ExtendedStatsAggregatorBuilder("foo"); + protected ExtendedStatsAggregatorBuilder doCreateTestAggregatorFactory() { + ExtendedStatsAggregatorBuilder factory = new ExtendedStatsAggregatorBuilder("foo"); if (randomBoolean()) { factory.sigma(randomDoubleBetween(0.0, 10.0, true)); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FilterTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FilterTests.java index 4b0389b0dce..8a6a4373691 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FilterTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FilterTests.java @@ -21,10 +21,9 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregator; -import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregator.FilterAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregatorBuilder; -public class FilterTests extends BaseAggregationTestCase { +public class FilterTests extends BaseAggregationTestCase { @Override protected FilterAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FiltersTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FiltersTests.java index 5ab91092973..1b30f7ad9ba 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FiltersTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/FiltersTests.java @@ -22,11 +22,10 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator; -import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.FiltersAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.KeyedFilter; +import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregatorBuilder; -public class FiltersTests extends BaseAggregationTestCase { +public class FiltersTests extends BaseAggregationTestCase { @Override protected FiltersAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsTests.java index ba8d22753a1..9bbd28c412d 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsTests.java @@ -20,10 +20,9 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregator; -import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregator.GeoBoundsAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregatorBuilder; -public class GeoBoundsTests extends BaseAggregationTestCase { +public class GeoBoundsTests extends BaseAggregationTestCase { @Override protected GeoBoundsAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidTests.java index 7bf21511e12..c912c18a82e 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoCentroidTests.java @@ -21,10 +21,9 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.script.Script; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregator; -import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregator.GeoCentroidAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregatorBuilder; -public class GeoCentroidTests extends BaseAggregationTestCase { +public class GeoCentroidTests extends BaseAggregationTestCase { @Override protected GeoCentroidAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxTests.java index 89b55605339..a9fe4654c9d 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxTests.java @@ -19,13 +19,13 @@ package org.elasticsearch.search.aggregations.metrics; -import org.elasticsearch.search.aggregations.metrics.max.MaxAggregator; +import org.elasticsearch.search.aggregations.metrics.max.MaxAggregatorBuilder; -public class MaxTests extends AbstractNumericMetricTestCase { +public class MaxTests extends AbstractNumericMetricTestCase { @Override - protected MaxAggregator.MaxAggregatorBuilder doCreateTestAggregatorFactory() { - return new MaxAggregator.MaxAggregatorBuilder("foo"); + protected MaxAggregatorBuilder doCreateTestAggregatorFactory() { + return new MaxAggregatorBuilder("foo"); } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MinTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MinTests.java index 5ee5db1671c..54512f579f3 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MinTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MinTests.java @@ -19,14 +19,13 @@ package org.elasticsearch.search.aggregations.metrics; -import org.elasticsearch.search.aggregations.metrics.min.MinAggregator; -import org.elasticsearch.search.aggregations.metrics.min.MinAggregator.MinAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.min.MinAggregatorBuilder; -public class MinTests extends AbstractNumericMetricTestCase { +public class MinTests extends AbstractNumericMetricTestCase { @Override protected MinAggregatorBuilder doCreateTestAggregatorFactory() { - return new MinAggregator.MinAggregatorBuilder("foo"); + return new MinAggregatorBuilder("foo"); } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MissingTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MissingTests.java index 846579f9c6b..3f49da5eb6e 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MissingTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MissingTests.java @@ -21,13 +21,13 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.script.Script; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.bucket.missing.MissingAggregator; +import org.elasticsearch.search.aggregations.bucket.missing.MissingAggregatorBuilder; -public class MissingTests extends BaseAggregationTestCase { +public class MissingTests extends BaseAggregationTestCase { @Override - protected final MissingAggregator.MissingAggregatorBuilder createTestAggregatorBuilder() { - MissingAggregator.MissingAggregatorBuilder factory = new MissingAggregator.MissingAggregatorBuilder("foo", null); + protected final MissingAggregatorBuilder createTestAggregatorBuilder() { + MissingAggregatorBuilder factory = new MissingAggregatorBuilder("foo", null); String field = randomNumericField(); int randomFieldBranch = randomInt(3); switch (randomFieldBranch) { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java index 6d4ae489979..a4e12b56d8e 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java @@ -22,13 +22,12 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregator; -import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregator.ScriptedMetricAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregatorBuilder; import java.util.HashMap; import java.util.Map; -public class ScriptedMetricTests extends BaseAggregationTestCase { +public class ScriptedMetricTests extends BaseAggregationTestCase { @Override protected ScriptedMetricAggregatorBuilder createTestAggregatorBuilder() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsTests.java index eaeca9cf123..5db4e1e332b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsTests.java @@ -19,13 +19,13 @@ package org.elasticsearch.search.aggregations.metrics; -import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregator; +import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregatorBuilder; -public class StatsTests extends AbstractNumericMetricTestCase { +public class StatsTests extends AbstractNumericMetricTestCase { @Override - protected StatsAggregator.StatsAggregatorBuilder doCreateTestAggregatorFactory() { - return new StatsAggregator.StatsAggregatorBuilder("foo"); + protected StatsAggregatorBuilder doCreateTestAggregatorFactory() { + return new StatsAggregatorBuilder("foo"); } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumTests.java index 78eba3499da..a6d9f0bd270 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumTests.java @@ -19,13 +19,13 @@ package org.elasticsearch.search.aggregations.metrics; -import org.elasticsearch.search.aggregations.metrics.sum.SumAggregator; +import org.elasticsearch.search.aggregations.metrics.sum.SumAggregatorBuilder; -public class SumTests extends AbstractNumericMetricTestCase { +public class SumTests extends AbstractNumericMetricTestCase { @Override - protected SumAggregator.SumAggregatorBuilder doCreateTestAggregatorFactory() { - return new SumAggregator.SumAggregatorBuilder("foo"); + protected SumAggregatorBuilder doCreateTestAggregatorFactory() { + return new SumAggregatorBuilder("foo"); } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsTests.java index 7636ccb73be..cccac925a1f 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsTests.java @@ -26,7 +26,7 @@ import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.script.Script; import org.elasticsearch.search.aggregations.AggregationInitializationException; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregator; +import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregatorBuilder; import org.elasticsearch.search.fetch.source.FetchSourceContext; import org.elasticsearch.search.highlight.HighlightBuilderTests; import org.elasticsearch.search.sort.SortBuilders; @@ -37,11 +37,11 @@ import java.util.List; import static org.hamcrest.Matchers.containsString; -public class TopHitsTests extends BaseAggregationTestCase { +public class TopHitsTests extends BaseAggregationTestCase { @Override - protected final TopHitsAggregator.TopHitsAggregatorBuilder createTestAggregatorBuilder() { - TopHitsAggregator.TopHitsAggregatorBuilder factory = new TopHitsAggregator.TopHitsAggregatorBuilder("foo"); + protected final TopHitsAggregatorBuilder createTestAggregatorBuilder() { + TopHitsAggregatorBuilder factory = new TopHitsAggregatorBuilder("foo"); if (randomBoolean()) { factory.from(randomIntBetween(0, 10000)); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountTests.java index a942aa4d34b..c9b601c4e8b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountTests.java @@ -21,13 +21,13 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.script.Script; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; -import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregator; +import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregatorBuilder; -public class ValueCountTests extends BaseAggregationTestCase { +public class ValueCountTests extends BaseAggregationTestCase { @Override - protected final ValueCountAggregator.ValueCountAggregatorBuilder createTestAggregatorBuilder() { - ValueCountAggregator.ValueCountAggregatorBuilder factory = new ValueCountAggregator.ValueCountAggregatorBuilder("foo", null); + protected final ValueCountAggregatorBuilder createTestAggregatorBuilder() { + ValueCountAggregatorBuilder factory = new ValueCountAggregatorBuilder("foo", null); String field = randomNumericField(); int randomFieldBranch = randomInt(3); switch (randomFieldBranch) { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptTests.java index 4226c5b6b2f..61b8117a0b0 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptTests.java @@ -23,14 +23,12 @@ import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator.BucketScriptPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregatorBuilder; import java.util.HashMap; import java.util.Map; -public class BucketScriptTests - extends BasePipelineAggregationTestCase { +public class BucketScriptTests extends BasePipelineAggregationTestCase { @Override protected BucketScriptPipelineAggregatorBuilder createTestAggregatorFactory() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorTests.java index 311ab3b9ca5..0f5e91f8d03 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorTests.java @@ -23,14 +23,12 @@ import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.having.BucketSelectorPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.having.BucketSelectorPipelineAggregator.BucketSelectorPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregatorBuilder; import java.util.HashMap; import java.util.Map; -public class BucketSelectorTests - extends BasePipelineAggregationTestCase { +public class BucketSelectorTests extends BasePipelineAggregationTestCase { @Override protected BucketSelectorPipelineAggregatorBuilder createTestAggregatorFactory() { @@ -58,5 +56,4 @@ public class BucketSelectorTests return factory; } - } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumTests.java index 8c3d1f693ef..6cb9bb936e6 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumTests.java @@ -20,11 +20,9 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; -import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregator.CumulativeSumPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregatorBuilder; -public class CumulativeSumTests - extends BasePipelineAggregationTestCase { +public class CumulativeSumTests extends BasePipelineAggregationTestCase { @Override protected CumulativeSumPipelineAggregatorBuilder createTestAggregatorFactory() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeTests.java index e1aa45f33e3..9ceac7b73a2 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/DerivativeTests.java @@ -21,10 +21,9 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator.DerivativePipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregatorBuilder; -public class DerivativeTests extends BasePipelineAggregationTestCase { +public class DerivativeTests extends BasePipelineAggregationTestCase { @Override protected DerivativePipelineAggregatorBuilder createTestAggregatorFactory() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregationHelperTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregationHelperTests.java index 1739b2b961f..43b3b4d357c 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregationHelperTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregationHelperTests.java @@ -20,10 +20,10 @@ package org.elasticsearch.search.aggregations.pipeline; -import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregator; -import org.elasticsearch.search.aggregations.metrics.max.MaxAggregator; -import org.elasticsearch.search.aggregations.metrics.min.MinAggregator; -import org.elasticsearch.search.aggregations.metrics.sum.SumAggregator; +import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.max.MaxAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.min.MinAggregatorBuilder; +import org.elasticsearch.search.aggregations.metrics.sum.SumAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.test.ESTestCase; @@ -111,25 +111,25 @@ public class PipelineAggregationHelperTests extends ESTestCase { */ public static double calculateMetric(double[] values, ValuesSourceAggregatorBuilder metric) { - if (metric instanceof MinAggregator.MinAggregatorBuilder) { + if (metric instanceof MinAggregatorBuilder) { double accumulator = Double.POSITIVE_INFINITY; for (double value : values) { accumulator = Math.min(accumulator, value); } return accumulator; - } else if (metric instanceof MaxAggregator.MaxAggregatorBuilder) { + } else if (metric instanceof MaxAggregatorBuilder) { double accumulator = Double.NEGATIVE_INFINITY; for (double value : values) { accumulator = Math.max(accumulator, value); } return accumulator; - } else if (metric instanceof SumAggregator.SumAggregatorBuilder) { + } else if (metric instanceof SumAggregatorBuilder) { double accumulator = 0; for (double value : values) { accumulator += value; } return accumulator; - } else if (metric instanceof AvgAggregator.AvgAggregatorBuilder) { + } else if (metric instanceof AvgAggregatorBuilder) { double accumulator = 0; for (double value : values) { accumulator += value; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/SerialDifferenceTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/SerialDifferenceTests.java index 9f03516846c..f7449192d5e 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/SerialDifferenceTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/SerialDifferenceTests.java @@ -21,11 +21,9 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator.SerialDiffPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregatorBuilder; -public class SerialDifferenceTests - extends BasePipelineAggregationTestCase { +public class SerialDifferenceTests extends BasePipelineAggregationTestCase { @Override protected SerialDiffPipelineAggregatorBuilder createTestAggregatorFactory() { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java index 6a7f013ebae..86bf5d92aca 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java @@ -19,10 +19,9 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregator.AvgBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregatorBuilder; -public class AvgBucketTests extends AbstractBucketMetricsTestCase { +public class AvgBucketTests extends AbstractBucketMetricsTestCase { @Override protected AvgBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java index dce0eb66e9c..f0e320d4e80 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java @@ -19,16 +19,13 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregatorBuilder; -public class ExtendedStatsBucketTests - extends AbstractBucketMetricsTestCase { +public class ExtendedStatsBucketTests extends AbstractBucketMetricsTestCase { @Override - protected ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, - String bucketsPath) { - ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder factory = - new ExtendedStatsBucketPipelineAggregator.ExtendedStatsBucketPipelineAggregatorBuilder(name, bucketsPath); + protected ExtendedStatsBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { + ExtendedStatsBucketPipelineAggregatorBuilder factory = new ExtendedStatsBucketPipelineAggregatorBuilder(name, bucketsPath); if (randomBoolean()) { factory.sigma(randomDoubleBetween(0.0, 10.0, false)); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MaxBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MaxBucketTests.java index f7bf7fd1c57..b7a531de748 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MaxBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MaxBucketTests.java @@ -19,10 +19,9 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregator.MaxBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregatorBuilder; -public class MaxBucketTests extends AbstractBucketMetricsTestCase { +public class MaxBucketTests extends AbstractBucketMetricsTestCase { @Override protected MaxBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java index 0df284cb4db..4e0befeb4a5 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java @@ -19,10 +19,9 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator.MinBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregatorBuilder; -public class MinBucketTests extends AbstractBucketMetricsTestCase { +public class MinBucketTests extends AbstractBucketMetricsTestCase { @Override protected MinBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java index b78515fa856..0ee57c309a1 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java @@ -19,16 +19,13 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregatorBuilder; -public class PercentilesBucketTests - extends AbstractBucketMetricsTestCase { +public class PercentilesBucketTests extends AbstractBucketMetricsTestCase { @Override - protected PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, - String bucketsPath) { - PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder factory = - new PercentilesBucketPipelineAggregator.PercentilesBucketPipelineAggregatorBuilder(name, bucketsPath); + protected PercentilesBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { + PercentilesBucketPipelineAggregatorBuilder factory = new PercentilesBucketPipelineAggregatorBuilder(name, bucketsPath); if (randomBoolean()) { int numPercents = randomIntBetween(1, 20); double[] percents = new double[numPercents]; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/StatsBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/StatsBucketTests.java index 2145ac077bf..f06d6621003 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/StatsBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/StatsBucketTests.java @@ -19,14 +19,14 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregatorBuilder; -public class StatsBucketTests extends AbstractBucketMetricsTestCase { +public class StatsBucketTests extends AbstractBucketMetricsTestCase { @Override - protected StatsBucketPipelineAggregator.StatsBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, + protected StatsBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { - return new StatsBucketPipelineAggregator.StatsBucketPipelineAggregatorBuilder(name, bucketsPath); + return new StatsBucketPipelineAggregatorBuilder(name, bucketsPath); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java index 0c0db16aecb..048d26bb612 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java @@ -19,10 +19,9 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator.SumBucketPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregatorBuilder; -public class SumBucketTests extends AbstractBucketMetricsTestCase { +public class SumBucketTests extends AbstractBucketMetricsTestCase { @Override protected SumBucketPipelineAggregatorBuilder doCreateTestAggregatorFactory(String name, String bucketsPath) { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java index db52a74cbee..87290bf0d79 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java @@ -21,8 +21,7 @@ package org.elasticsearch.search.aggregations.pipeline.moving.avg; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator.MovAvgPipelineAggregatorBuilder; +import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.movavg.models.EwmaModel; import org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltLinearModel; import org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltWintersModel; @@ -30,7 +29,7 @@ import org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltWintersM import org.elasticsearch.search.aggregations.pipeline.movavg.models.LinearModel; import org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel;; -public class MovAvgTests extends BasePipelineAggregationTestCase { +public class MovAvgTests extends BasePipelineAggregationTestCase { @Override protected MovAvgPipelineAggregatorBuilder createTestAggregatorFactory() { diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/EquivalenceTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/EquivalenceTests.java index e1b4820c015..bf67d8bc8e8 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/EquivalenceTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/EquivalenceTests.java @@ -35,8 +35,8 @@ import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.range.Range; -import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator; import org.elasticsearch.search.aggregations.bucket.range.Range.Bucket; +import org.elasticsearch.search.aggregations.bucket.range.RangeAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorFactory; import org.elasticsearch.search.aggregations.metrics.sum.Sum; @@ -122,7 +122,7 @@ public class EquivalenceTests extends ESIntegTestCase { } } - RangeAggregator.RangeAggregatorBuilder query = range("range").field("values"); + RangeAggregatorBuilder query = range("range").field("values"); for (int i = 0; i < ranges.length; ++i) { String key = Integer.toString(i); if (ranges[i][0] == Double.NEGATIVE_INFINITY) {