diff --git a/src/main/java/org/elasticsearch/action/count/CountRequest.java b/src/main/java/org/elasticsearch/action/count/CountRequest.java index c85ef0612c3..07ef5a96a00 100644 --- a/src/main/java/org/elasticsearch/action/count/CountRequest.java +++ b/src/main/java/org/elasticsearch/action/count/CountRequest.java @@ -62,6 +62,9 @@ public class CountRequest extends BroadcastOperationRequest { @Nullable protected String routing; + @Nullable + private String preference; + private BytesReference querySource; private boolean querySourceUnsafe; @@ -220,6 +223,15 @@ public class CountRequest extends BroadcastOperationRequest { return this; } + public CountRequest preference(String preference) { + this.preference = preference; + return this; + } + + public String preference() { + return this.preference; + } + @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); diff --git a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java index 6559d1a9a82..f7e3527a3f4 100644 --- a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java +++ b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java @@ -104,7 +104,7 @@ public class TransportCountAction extends TransportBroadcastOperationAction> 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 diff --git a/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java b/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java index bd16d210536..dbc91142617 100644 --- a/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java +++ b/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java @@ -89,6 +89,7 @@ public class RestCountAction extends BaseRestHandler { countRequest.routing(request.param("routing")); countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE)); countRequest.types(splitTypes(request.param("type"))); + countRequest.preference(request.param("preference")); } catch (Exception e) { try { XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);