From f3114fe7749b42b610b4e1dd1e7f82145f08cbc9 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 21 Jul 2014 11:21:50 +0200 Subject: [PATCH] [TEST] top_hits aggs with breath_first collect mode only fails if scoring is used (score based sort or track_scores) --- .../search/aggregations/bucket/TopHitsTests.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 0fbe2a1428d..edc438216f9 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java @@ -413,15 +413,25 @@ public class TopHitsTests extends ElasticsearchIntegrationTest { } @Test - public void testFailDeferred() throws Exception { - + public void testFailDeferredOnlyWhenScorerIsUsed() throws Exception { + // No track_scores or score based sort defined in top_hits agg, so don't fail: + SearchResponse response = client().prepareSearch("idx") + .setTypes("type") + .addAggregation( + terms("terms").executionHint(randomExecutionHint()).field(TERMS_AGGS_FIELD) + .collectMode(SubAggCollectionMode.BREADTH_FIRST) + .subAggregation(topHits("hits").addSort(SortBuilders.fieldSort(SORT_FIELD).order(SortOrder.DESC)))) + .get(); + assertSearchResponse(response); + + // Score based, so fail with deferred aggs: try { client().prepareSearch("idx") .setTypes("type") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(TERMS_AGGS_FIELD) .collectMode(SubAggCollectionMode.BREADTH_FIRST) - .subAggregation(topHits("hits").addSort(SortBuilders.fieldSort(SORT_FIELD).order(SortOrder.DESC)))) + .subAggregation(topHits("hits"))) .get(); fail(); } catch (Exception e) {