diff --git a/src/main/java/org/elasticsearch/action/count/CountRequest.java b/src/main/java/org/elasticsearch/action/count/CountRequest.java index 07ef5a96a00..d25e01e02dc 100644 --- a/src/main/java/org/elasticsearch/action/count/CountRequest.java +++ b/src/main/java/org/elasticsearch/action/count/CountRequest.java @@ -237,6 +237,7 @@ public class CountRequest extends BroadcastOperationRequest { super.readFrom(in); minScore = in.readFloat(); routing = in.readOptionalString(); + preference = in.readOptionalString(); querySourceUnsafe = false; querySource = in.readBytesReference(); types = in.readStringArray(); @@ -247,6 +248,7 @@ public class CountRequest extends BroadcastOperationRequest { super.writeTo(out); out.writeFloat(minScore); out.writeOptionalString(routing); + out.writeOptionalString(preference); out.writeBytesReference(querySource); out.writeStringArray(types); } diff --git a/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java b/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java index 83271b1177b..d31bb7935d1 100644 --- a/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java @@ -60,6 +60,17 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder_local to prefer local shards, _primary to execute only on primary shards, + * _shards:x,y to operate on shards x & y, or a custom value, which guarantees that the same order + * will be used across different requests. + */ + public CountRequestBuilder setPreference(String preference) { + request.preference(preference); + return this; + } + /** * The routing values to control the shards that the search will be executed on. */