Count api: simplify default handling

For minScore and terminateAfter we can just rely on defaults set to SearchSourceBuilder.
This commit is contained in:
javanna 2015-10-06 15:55:18 +02:00 committed by Luca Cavanna
parent 10a559348b
commit fcc60609ae
2 changed files with 4 additions and 8 deletions

View File

@ -31,8 +31,6 @@ 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...)}.
@ -43,8 +41,6 @@ import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_
*/
public class CountRequest extends BroadcastRequest<CountRequest> {
public static final float DEFAULT_MIN_SCORE = -1f;
@Nullable
protected String routing;
@ -62,8 +58,6 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
public CountRequest(String... indices) {
super(indices);
searchSourceBuilder.size(0);
searchSourceBuilder.minScore(DEFAULT_MIN_SCORE);
searchSourceBuilder.terminateAfter(DEFAULT_TERMINATE_AFTER);
}
/**

View File

@ -45,7 +45,6 @@ import org.elasticsearch.rest.action.support.RestBuilderListener;
import java.io.IOException;
import static org.elasticsearch.action.count.CountRequest.DEFAULT_MIN_SCORE;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.action.support.RestActions.buildBroadcastShardsHeader;
@ -91,7 +90,10 @@ public class RestCountAction extends BaseRestHandler {
}
}
countRequest.routing(request.param("routing"));
countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
float minScore = request.paramAsFloat("min_score", -1f);
if (minScore != -1f) {
countRequest.minScore(minScore);
}
countRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
countRequest.preference(request.param("preference"));