Allow _count to take preference parameter. [#2698]

This commit is contained in:
Drew Raines 2013-02-26 16:22:49 -06:00 committed by Drew Raines
parent 1e937fd5d1
commit b53a8aff6a
3 changed files with 14 additions and 1 deletions

View File

@ -62,6 +62,9 @@ public class CountRequest extends BroadcastOperationRequest<CountRequest> {
@Nullable @Nullable
protected String routing; protected String routing;
@Nullable
private String preference;
private BytesReference querySource; private BytesReference querySource;
private boolean querySourceUnsafe; private boolean querySourceUnsafe;
@ -220,6 +223,15 @@ public class CountRequest extends BroadcastOperationRequest<CountRequest> {
return this; return this;
} }
public CountRequest preference(String preference) {
this.preference = preference;
return this;
}
public String preference() {
return this.preference;
}
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);

View File

@ -104,7 +104,7 @@ public class TransportCountAction extends TransportBroadcastOperationAction<Coun
@Override @Override
protected GroupShardsIterator shards(ClusterState clusterState, CountRequest request, String[] concreteIndices) { protected GroupShardsIterator shards(ClusterState clusterState, CountRequest request, String[] concreteIndices) {
Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(request.routing(), request.indices()); Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting(request.routing(), request.indices());
return clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, routingMap, null); return clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, routingMap, request.preference());
} }
@Override @Override

View File

@ -89,6 +89,7 @@ public class RestCountAction extends BaseRestHandler {
countRequest.routing(request.param("routing")); countRequest.routing(request.param("routing"));
countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE)); countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
countRequest.types(splitTypes(request.param("type"))); countRequest.types(splitTypes(request.param("type")));
countRequest.preference(request.param("preference"));
} catch (Exception e) { } catch (Exception e) {
try { try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);