Count api: simplify default handling
For minScore and terminateAfter we can just rely on defaults set to SearchSourceBuilder.
This commit is contained in:
parent
10a559348b
commit
fcc60609ae
|
@ -31,8 +31,6 @@ 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...)}.
|
||||||
|
@ -43,8 +41,6 @@ import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_
|
||||||
*/
|
*/
|
||||||
public class CountRequest extends BroadcastRequest<CountRequest> {
|
public class CountRequest extends BroadcastRequest<CountRequest> {
|
||||||
|
|
||||||
public static final float DEFAULT_MIN_SCORE = -1f;
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
protected String routing;
|
protected String routing;
|
||||||
|
|
||||||
|
@ -62,8 +58,6 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
||||||
public CountRequest(String... indices) {
|
public CountRequest(String... indices) {
|
||||||
super(indices);
|
super(indices);
|
||||||
searchSourceBuilder.size(0);
|
searchSourceBuilder.size(0);
|
||||||
searchSourceBuilder.minScore(DEFAULT_MIN_SCORE);
|
|
||||||
searchSourceBuilder.terminateAfter(DEFAULT_TERMINATE_AFTER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -45,7 +45,6 @@ import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.GET;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.action.support.RestActions.buildBroadcastShardsHeader;
|
import static org.elasticsearch.rest.action.support.RestActions.buildBroadcastShardsHeader;
|
||||||
|
@ -91,7 +90,10 @@ public class RestCountAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
countRequest.routing(request.param("routing"));
|
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.types(Strings.splitStringByCommaToArray(request.param("type")));
|
||||||
countRequest.preference(request.param("preference"));
|
countRequest.preference(request.param("preference"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue