Set subSearchContext.topDocs after the rescoring in TopDocsAggs

This change fixes a bug introduced in https://github.com/elastic/elasticsearch/pull/20978
The top docs should be set in the subSearchContext after the rescoring
This commit is contained in:
Jim Ferenczi 2016-10-21 11:01:17 +02:00
parent 5495b66797
commit 05915357c9
1 changed files with 2 additions and 2 deletions

View File

@ -141,7 +141,6 @@ public class TopHitsAggregator extends MetricsAggregator {
topHits = buildEmptyAggregation(); topHits = buildEmptyAggregation();
} else { } else {
TopDocs topDocs = topDocsCollector.topLevelCollector.topDocs(); TopDocs topDocs = topDocsCollector.topLevelCollector.topDocs();
subSearchContext.queryResult().topDocs(topDocs, subSearchContext.sort() == null ? null : subSearchContext.sort().formats);
if (subSearchContext.sort() == null) { if (subSearchContext.sort() == null) {
for (RescoreSearchContext ctx : context().searchContext().rescore()) { for (RescoreSearchContext ctx : context().searchContext().rescore()) {
try { try {
@ -151,7 +150,8 @@ public class TopHitsAggregator extends MetricsAggregator {
} }
} }
} }
subSearchContext.queryResult().topDocs(topDocs,
subSearchContext.sort() == null ? null : subSearchContext.sort().formats);
int[] docIdsToLoad = new int[topDocs.scoreDocs.length]; int[] docIdsToLoad = new int[topDocs.scoreDocs.length];
for (int i = 0; i < topDocs.scoreDocs.length; i++) { for (int i = 0; i < topDocs.scoreDocs.length; i++) {
docIdsToLoad[i] = topDocs.scoreDocs[i].doc; docIdsToLoad[i] = topDocs.scoreDocs[i].doc;