Revert "Count api: simplify default handling and toString representation"
This reverts commit ef286ce972
.
This commit is contained in:
parent
ef286ce972
commit
80d236e1a0
|
@ -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...)}.
|
||||
|
@ -42,6 +44,8 @@ import java.util.Arrays;
|
|||
*/
|
||||
public class CountRequest extends BroadcastRequest<CountRequest> {
|
||||
|
||||
public static final float DEFAULT_MIN_SCORE = -1f;
|
||||
|
||||
@Nullable
|
||||
protected String routing;
|
||||
|
||||
|
@ -59,6 +63,8 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,6 +83,7 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The query to execute
|
||||
*/
|
||||
|
@ -165,6 +172,10 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", source[" + sSource + "]";
|
||||
}
|
||||
|
||||
public String sourceBuilderString() {
|
||||
return searchSourceBuilder.toString();
|
||||
}
|
||||
|
||||
public SearchRequest toSearchRequest() {
|
||||
SearchRequest searchRequest = new SearchRequest(indices());
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
|
|
|
@ -106,6 +106,6 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder<CountR
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return request.toString();
|
||||
return request.sourceBuilderString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ 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;
|
||||
|
@ -90,10 +91,7 @@ public class RestCountAction extends BaseRestHandler {
|
|||
}
|
||||
}
|
||||
countRequest.routing(request.param("routing"));
|
||||
float minScore = request.paramAsFloat("min_score", -1f);
|
||||
if (minScore != -1f) {
|
||||
countRequest.minScore(minScore);
|
||||
}
|
||||
countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
|
||||
countRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
|
||||
countRequest.preference(request.param("preference"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue