From 8f1b063e0a3516e358caf377c19371ac3e8cd8ff Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Fri, 18 Jan 2019 10:44:59 +0100 Subject: [PATCH] expand TopDocsStats to include timedOut and earlyTerminated This allows to share more code between SearchResponseMerger and SearchPhaseController --- .../action/search/SearchPhaseController.java | 34 +++++++++---------- .../action/search/SearchResponseMerger.java | 11 ++---- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java b/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java index 2380b5b6f32be..027d9d5f10c25 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java @@ -170,7 +170,7 @@ static SortedTopDocs sortDocs(boolean ignoreFrom, Collection 0) { setShardIndex(td.topDocs, queryResult.getShardIndex()); @@ -439,12 +439,10 @@ private ReducedQueryPhase reducedQueryPhase(Collection= 0 : "num reduce phases must be >= 0 but was: " + numReducePhases; numReducePhases++; // increment for this phase - boolean timedOut = false; - Boolean terminatedEarly = null; if (queryResults.isEmpty()) { // early terminate we have nothing to reduce final TotalHits totalHits = topDocsStats.getTotalHits(); return new ReducedQueryPhase(totalHits, topDocsStats.fetchHits, topDocsStats.getMaxScore(), - timedOut, terminatedEarly, null, null, null, SortedTopDocs.EMPTY, null, numReducePhases, 0, 0, true); + false, null, null, null, null, SortedTopDocs.EMPTY, null, numReducePhases, 0, 0, true); } final QuerySearchResult firstResult = queryResults.stream().findFirst().get().queryResult(); final boolean hasSuggest = firstResult.suggest() != null; @@ -476,16 +474,6 @@ private ReducedQueryPhase reducedQueryPhase(Collection> suggestion : result.suggest()) { @@ -509,7 +497,7 @@ private ReducedQueryPhase reducedQueryPhase(Collection failures = new ArrayList<>(); @@ -121,10 +119,6 @@ SearchResponse getMergedResponse() { totalShards += searchResponse.getTotalShards(); skippedShards += searchResponse.getSkippedShards(); successfulShards += searchResponse.getSuccessfulShards(); - timedOut = timedOut || searchResponse.isTimedOut(); - if (searchResponse.isTerminatedEarly() != null && searchResponse.isTerminatedEarly()) { - terminatedEarly = true; - } numReducePhases += searchResponse.getNumReducePhases(); Collections.addAll(failures, searchResponse.getShardFailures()); @@ -158,7 +152,8 @@ SearchResponse getMergedResponse() { trackTotalHits = true; } TopDocs topDocs = searchHitsToTopDocs(searchHits, totalHits, shards); - topDocsStats.add(new TopDocsAndMaxScore(topDocs, searchHits.getMaxScore())); + topDocsStats.add(new TopDocsAndMaxScore(topDocs, searchHits.getMaxScore()), + searchResponse.isTimedOut(), searchResponse.isTerminatedEarly()); topDocsList.add(topDocs); } @@ -186,7 +181,7 @@ SearchResponse getMergedResponse() { //make failures ordering consistent with ordinary search and CCS Arrays.sort(shardFailures, FAILURES_COMPARATOR); InternalSearchResponse response = new InternalSearchResponse(mergedSearchHits, reducedAggs, suggest, - new SearchProfileShardResults(profileResults), timedOut, terminatedEarly, numReducePhases); + new SearchProfileShardResults(profileResults), topDocsStats.timedOut, topDocsStats.terminatedEarly, numReducePhases); long tookInMillis = searchTimeProvider.buildTookInMillis(); return new SearchResponse(response, null, totalShards, successfulShards, skippedShards, tookInMillis, shardFailures, clusters); }