diff --git a/docs/reference/search/aggregations/bucket.asciidoc b/docs/reference/search/aggregations/bucket.asciidoc index 86bc9957200..ceb8e15ee19 100644 --- a/docs/reference/search/aggregations/bucket.asciidoc +++ b/docs/reference/search/aggregations/bucket.asciidoc @@ -27,5 +27,3 @@ include::bucket/datehistogram-aggregation.asciidoc[] include::bucket/geodistance-aggregation.asciidoc[] include::bucket/geohashgrid-aggregation.asciidoc[] - -include::bucket/tophits-aggregation.asciidoc[] \ No newline at end of file diff --git a/docs/reference/search/aggregations/metrics.asciidoc b/docs/reference/search/aggregations/metrics.asciidoc index bb3671d5b5c..f338a6a8094 100644 --- a/docs/reference/search/aggregations/metrics.asciidoc +++ b/docs/reference/search/aggregations/metrics.asciidoc @@ -19,3 +19,5 @@ include::metrics/percentile-aggregation.asciidoc[] include::metrics/cardinality-aggregation.asciidoc[] include::metrics/geobounds-aggregation.asciidoc[] + +include::metrics/tophits-aggregation.asciidoc[] diff --git a/docs/reference/search/aggregations/bucket/tophits-aggregation.asciidoc b/docs/reference/search/aggregations/metrics/tophits-aggregation.asciidoc similarity index 94% rename from docs/reference/search/aggregations/bucket/tophits-aggregation.asciidoc rename to docs/reference/search/aggregations/metrics/tophits-aggregation.asciidoc index e7db5ab2433..d9174d0be63 100644 --- a/docs/reference/search/aggregations/bucket/tophits-aggregation.asciidoc +++ b/docs/reference/search/aggregations/metrics/tophits-aggregation.asciidoc @@ -1,16 +1,14 @@ -[[search-aggregations-bucket-top-hits-aggregation]] +[[search-aggregations-metrics-top-hits-aggregation]] === Top hits Aggregation coming[1.3.0] -The `top_hits` aggregator keeps track of the most relevant document being aggregated. This aggregator is intended to be -used as a sub aggregator, so that the top matching documents can be aggregated per bucket. +A `top_hits` metric aggregator keeps track of the most relevant document being aggregated. This aggregator is intended +to be used as a sub aggregator, so that the top matching documents can be aggregated per bucket. The `top_hits` aggregator can effectively be used to group result sets by certain fields via a bucket aggregator. One or more bucket aggregators determines by which properties a result set get sliced into. -This aggregator can't hold any sub-aggregators and therefor can only be used as a leaf aggregator. - ==== Options * `from` - The offset from the first result you want to fetch. diff --git a/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilders.java b/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilders.java index 57683cd33e1..478a27d59be 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilders.java +++ b/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilders.java @@ -32,7 +32,7 @@ import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanc import org.elasticsearch.search.aggregations.bucket.range.ipv4.IPv4RangeBuilder; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; -import org.elasticsearch.search.aggregations.bucket.tophits.TopHitsBuilder; +import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsBuilder; import org.elasticsearch.search.aggregations.metrics.avg.AvgBuilder; import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityBuilder; import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsBuilder; diff --git a/src/main/java/org/elasticsearch/search/aggregations/AggregationModule.java b/src/main/java/org/elasticsearch/search/aggregations/AggregationModule.java index a51583aa53f..08eac3402b9 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/AggregationModule.java +++ b/src/main/java/org/elasticsearch/search/aggregations/AggregationModule.java @@ -35,7 +35,7 @@ import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanc import org.elasticsearch.search.aggregations.bucket.range.ipv4.IpRangeParser; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsParser; import org.elasticsearch.search.aggregations.bucket.terms.TermsParser; -import org.elasticsearch.search.aggregations.bucket.tophits.TopHitsParser; +import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsParser; import org.elasticsearch.search.aggregations.metrics.avg.AvgParser; import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityParser; import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsParser; diff --git a/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java b/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java index 68acb3c376c..e7936ff29a4 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java +++ b/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java @@ -38,7 +38,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.DoubleTerms; import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; import org.elasticsearch.search.aggregations.bucket.terms.UnmappedTerms; -import org.elasticsearch.search.aggregations.bucket.tophits.InternalTopHits; +import org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHits; import org.elasticsearch.search.aggregations.metrics.avg.InternalAvg; import org.elasticsearch.search.aggregations.metrics.cardinality.InternalCardinality; import org.elasticsearch.search.aggregations.metrics.geobounds.InternalGeoBounds; diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/InternalTopHits.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHits.java similarity index 95% rename from src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/InternalTopHits.java rename to src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHits.java index c54eadbfa50..a1ce92490ef 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/InternalTopHits.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHits.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.search.aggregations.bucket.tophits; +package org.elasticsearch.search.aggregations.metrics.tophits; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; @@ -25,13 +25,12 @@ import org.apache.lucene.search.TopFieldDocs; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.AggregationStreams; import org.elasticsearch.search.aggregations.InternalAggregation; +import org.elasticsearch.search.aggregations.metrics.InternalMetricsAggregation; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.InternalSearchHits; @@ -40,7 +39,7 @@ import java.util.List; /** */ -public class InternalTopHits extends InternalAggregation implements TopHits, ToXContent, Streamable { +public class InternalTopHits extends InternalMetricsAggregation implements TopHits { public static final InternalAggregation.Type TYPE = new Type("top_hits"); diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHits.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHits.java similarity index 94% rename from src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHits.java rename to src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHits.java index 4c20e430b9a..565a80a13c8 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHits.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHits.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.search.aggregations.bucket.tophits; +package org.elasticsearch.search.aggregations.metrics.tophits; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.Aggregation; diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java similarity index 95% rename from src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsAggregator.java rename to src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java index 5ea62de1484..c85838c3b37 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.search.aggregations.bucket.tophits; +package org.elasticsearch.search.aggregations.metrics.tophits; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.*; @@ -27,7 +27,7 @@ import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.ScorerAware; import org.elasticsearch.common.util.LongObjectPagedHashMap; import org.elasticsearch.search.aggregations.*; -import org.elasticsearch.search.aggregations.bucket.BucketsAggregator; +import org.elasticsearch.search.aggregations.metrics.MetricsAggregator; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.fetch.FetchPhase; import org.elasticsearch.search.fetch.FetchSearchResult; @@ -38,7 +38,7 @@ import java.io.IOException; /** */ -public class TopHitsAggregator extends BucketsAggregator implements ScorerAware { +public class TopHitsAggregator extends MetricsAggregator implements ScorerAware { private final FetchPhase fetchPhase; private final TopHitsContext topHitsContext; @@ -48,7 +48,7 @@ public class TopHitsAggregator extends BucketsAggregator implements ScorerAware private AtomicReaderContext currentContext; public TopHitsAggregator(FetchPhase fetchPhase, TopHitsContext topHitsContext, String name, long estimatedBucketsCount, AggregationContext context, Aggregator parent) { - super(name, BucketAggregationMode.MULTI_BUCKETS, AggregatorFactories.EMPTY, estimatedBucketsCount, context, parent); + super(name, estimatedBucketsCount, context, parent); this.fetchPhase = fetchPhase; topDocsCollectors = new LongObjectPagedHashMap<>(estimatedBucketsCount, context.bigArrays()); this.topHitsContext = topHitsContext; diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsBuilder.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsBuilder.java similarity index 99% rename from src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsBuilder.java rename to src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsBuilder.java index 767158be0b0..4521bd3f0f1 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsBuilder.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsBuilder.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.search.aggregations.bucket.tophits; +package org.elasticsearch.search.aggregations.metrics.tophits; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsContext.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsContext.java similarity index 99% rename from src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsContext.java rename to src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsContext.java index 2023b4c9668..bf53eed8413 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsContext.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsContext.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.search.aggregations.bucket.tophits; +package org.elasticsearch.search.aggregations.metrics.tophits; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsParser.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsParser.java similarity index 99% rename from src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsParser.java rename to src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsParser.java index cfd93bb4f2d..4a4b60ad8d8 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/tophits/TopHitsParser.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsParser.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.search.aggregations.bucket.tophits; +package org.elasticsearch.search.aggregations.metrics.tophits; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.inject.Inject; diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java index 22ab5ca9943..fb9f52a866e 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java @@ -30,7 +30,7 @@ import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorFactory.ExecutionMode; -import org.elasticsearch.search.aggregations.bucket.tophits.TopHits; +import org.elasticsearch.search.aggregations.metrics.tophits.TopHits; import org.elasticsearch.search.aggregations.metrics.max.Max; import org.elasticsearch.search.highlight.HighlightField; import org.elasticsearch.search.sort.SortBuilders;