From ec93531303d02adef1dc2f9dd8d6a212ea7a3054 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Mon, 5 Oct 2015 14:28:25 +0100 Subject: [PATCH] fixes --- .../org/elasticsearch/action/count/CountRequest.java | 12 +++++------- .../search/builder/SearchSourceBuilder.java | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/count/CountRequest.java b/core/src/main/java/org/elasticsearch/action/count/CountRequest.java index 2e8985c17d8..29638b2f7aa 100644 --- a/core/src/main/java/org/elasticsearch/action/count/CountRequest.java +++ b/core/src/main/java/org/elasticsearch/action/count/CountRequest.java @@ -32,6 +32,8 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import java.io.IOException; import java.util.Arrays; +import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER; + /** * A request to count the number of documents matching a specific query. Best created with * {@link org.elasticsearch.client.Requests#countRequest(String...)}. @@ -54,16 +56,15 @@ public class CountRequest extends BroadcastRequest { private SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - public CountRequest() { - searchSourceBuilder.size(0); - } - /** * Constructs a new count request against the provided indices. No indices provided means it will * run against all indices. */ public CountRequest(String... indices) { super(indices); + searchSourceBuilder.size(0); + searchSourceBuilder.minScore(DEFAULT_MIN_SCORE); + searchSourceBuilder.terminateAfter(DEFAULT_TERMINATE_AFTER); } /** @@ -142,9 +143,6 @@ public class CountRequest extends BroadcastRequest { * Upon reaching terminateAfter counts, the count request will early terminate */ public CountRequest terminateAfter(int terminateAfterCount) { - if (terminateAfterCount <= 0) { - throw new IllegalArgumentException("terminateAfter must be > 0"); - } this.searchSourceBuilder.terminateAfter(terminateAfterCount); return this; } diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 8b2a00c669d..51d2b6a6d5d 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -293,7 +293,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ * terminateAfter documents */ public SearchSourceBuilder terminateAfter(int terminateAfter) { - if (terminateAfter <= 0) { + if (terminateAfter < 0) { throw new IllegalArgumentException("terminateAfter must be > 0"); } this.terminateAfter = terminateAfter;