From b53a8aff6a0df645d5335ac3982ecedee951b464 Mon Sep 17 00:00:00 2001 From: Drew Raines Date: Tue, 26 Feb 2013 16:22:49 -0600 Subject: [PATCH] Allow _count to take preference parameter. [#2698] --- .../org/elasticsearch/action/count/CountRequest.java | 12 ++++++++++++ .../action/count/TransportCountAction.java | 2 +- .../rest/action/count/RestCountAction.java | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) 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);