This commit is contained in:
Colin Goodheart-Smithe 2015-10-05 14:28:25 +01:00
parent 7055a05e6e
commit ec93531303
2 changed files with 6 additions and 8 deletions

View File

@ -32,6 +32,8 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; 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 * A request to count the number of documents matching a specific query. Best created with
* {@link org.elasticsearch.client.Requests#countRequest(String...)}. * {@link org.elasticsearch.client.Requests#countRequest(String...)}.
@ -54,16 +56,15 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
private SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); 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 * Constructs a new count request against the provided indices. No indices provided means it will
* run against all indices. * run against all indices.
*/ */
public CountRequest(String... indices) { public CountRequest(String... indices) {
super(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<CountRequest> {
* Upon reaching <code>terminateAfter</code> counts, the count request will early terminate * Upon reaching <code>terminateAfter</code> counts, the count request will early terminate
*/ */
public CountRequest terminateAfter(int terminateAfterCount) { public CountRequest terminateAfter(int terminateAfterCount) {
if (terminateAfterCount <= 0) {
throw new IllegalArgumentException("terminateAfter must be > 0");
}
this.searchSourceBuilder.terminateAfter(terminateAfterCount); this.searchSourceBuilder.terminateAfter(terminateAfterCount);
return this; return this;
} }

View File

@ -293,7 +293,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
* <code>terminateAfter</code> documents * <code>terminateAfter</code> documents
*/ */
public SearchSourceBuilder terminateAfter(int terminateAfter) { public SearchSourceBuilder terminateAfter(int terminateAfter) {
if (terminateAfter <= 0) { if (terminateAfter < 0) {
throw new IllegalArgumentException("terminateAfter must be > 0"); throw new IllegalArgumentException("terminateAfter must be > 0");
} }
this.terminateAfter = terminateAfter; this.terminateAfter = terminateAfter;