summaryrefslogtreecommitdiff
path: root/test/framework
diff options
context:
space:
mode:
authorJim Ferenczi <jim.ferenczi@elastic.co>2017-06-08 12:10:46 +0200
committerGitHub <noreply@github.com>2017-06-08 12:10:46 +0200
commit36a5cf8f35e5cbaa1ff857b5a5db8c02edc1a187 (patch)
tree500eaf53b1f42a7b23171ca2cbb029e4b18da579 /test/framework
parent21a57c14945fb0b82d2b78a2c89e0d92bbc086a0 (diff)
Automatically early terminate search query based on index sorting (#24864)
This commit refactors the query phase in order to be able to automatically detect queries that can be early terminated. If the index sort matches the query sort, the top docs collection is early terminated on each segment and the computing of the total number of hits that match the query is delegated to a simple TotalHitCountCollector. This change also adds a new parameter to the search request called `track_total_hits`. It indicates if the total number of hits that match the query should be tracked. If false, queries sorted by the index sort will not try to compute this information and and will limit the collection to the first N documents per segment. Aggregations are not impacted and will continue to see every document even when the index sort matches the query sort and `track_total_hits` is false. Relates #6720
Diffstat (limited to 'test/framework')
-rw-r--r--test/framework/src/main/java/org/elasticsearch/search/RandomSearchRequestGenerator.java3
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java33
2 files changed, 29 insertions, 7 deletions
diff --git a/test/framework/src/main/java/org/elasticsearch/search/RandomSearchRequestGenerator.java b/test/framework/src/main/java/org/elasticsearch/search/RandomSearchRequestGenerator.java
index 4cd46fe507..e4f5f2cc39 100644
--- a/test/framework/src/main/java/org/elasticsearch/search/RandomSearchRequestGenerator.java
+++ b/test/framework/src/main/java/org/elasticsearch/search/RandomSearchRequestGenerator.java
@@ -143,6 +143,9 @@ public class RandomSearchRequestGenerator {
if (randomBoolean()) {
builder.terminateAfter(randomIntBetween(1, 100000));
}
+ if (randomBoolean()) {
+ builder.trackTotalHits(randomBoolean());
+ }
switch(randomInt(2)) {
case 0:
diff --git a/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java b/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java
index f77414e7d5..038a21c28e 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java
@@ -60,6 +60,7 @@ import org.elasticsearch.search.sort.SortAndFormats;
import org.elasticsearch.search.suggest.SuggestionSearchContext;
import org.elasticsearch.threadpool.ThreadPool;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -81,11 +82,15 @@ public class TestSearchContext extends SearchContext {
Query query;
Float minScore;
SearchTask task;
+ SortAndFormats sort;
+ boolean trackScores = false;
+ boolean trackTotalHits = true;
ContextIndexSearcher searcher;
int size;
private int terminateAfter = DEFAULT_TERMINATE_AFTER;
private SearchContextAggregations aggregations;
+ private ScrollContext scrollContext;
private final long originNanoTime = System.nanoTime();
private final Map<String, SearchExtBuilder> searchExtBuilders = new HashMap<>();
@@ -161,12 +166,13 @@ public class TestSearchContext extends SearchContext {
@Override
public ScrollContext scrollContext() {
- return null;
+ return scrollContext;
}
@Override
public SearchContext scrollContext(ScrollContext scrollContext) {
- throw new UnsupportedOperationException();
+ this.scrollContext = scrollContext;
+ return this;
}
@Override
@@ -210,7 +216,7 @@ public class TestSearchContext extends SearchContext {
@Override
public List<RescoreSearchContext> rescore() {
- return null;
+ return Collections.emptyList();
}
@Override
@@ -336,22 +342,35 @@ public class TestSearchContext extends SearchContext {
@Override
public SearchContext sort(SortAndFormats sort) {
- return null;
+ this.sort = sort;
+ return this;
}
@Override
public SortAndFormats sort() {
- return null;
+ return sort;
}
@Override
public SearchContext trackScores(boolean trackScores) {
- return null;
+ this.trackScores = trackScores;
+ return this;
}
@Override
public boolean trackScores() {
- return false;
+ return trackScores;
+ }
+
+ @Override
+ public SearchContext trackTotalHits(boolean trackTotalHits) {
+ this.trackTotalHits = trackTotalHits;
+ return this;
+ }
+
+ @Override
+ public boolean trackTotalHits() {
+ return trackTotalHits;
}
@Override