diff --git a/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java b/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java index 45eca14c9f2..1be27f45dbd 100644 --- a/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java +++ b/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java @@ -214,7 +214,8 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio .source(source, sourceAndContent.v1()) .version(getResult.version()).replicationType(request.replicationType()).consistencyLevel(request.consistencyLevel()) .timestamp(timestamp).ttl(ttl) - .percolate(request.percolate()); + .percolate(request.percolate()) + .refresh(request.refresh()); indexRequest.operationThreaded(false); indexAction.execute(indexRequest, new ActionListener() { @Override diff --git a/src/main/java/org/elasticsearch/action/update/UpdateRequest.java b/src/main/java/org/elasticsearch/action/update/UpdateRequest.java index 2dfe33cb435..d7e823b7ad3 100644 --- a/src/main/java/org/elasticsearch/action/update/UpdateRequest.java +++ b/src/main/java/org/elasticsearch/action/update/UpdateRequest.java @@ -53,6 +53,8 @@ public class UpdateRequest extends InstanceShardOperationRequest { private String percolate; + private boolean refresh = false; + private ReplicationType replicationType = ReplicationType.DEFAULT; private WriteConsistencyLevel consistencyLevel = WriteConsistencyLevel.DEFAULT; @@ -270,6 +272,20 @@ public class UpdateRequest extends InstanceShardOperationRequest { return timeout(TimeValue.parseTimeValue(timeout, null)); } + /** + * Should a refresh be executed post this update operation causing the operation to + * be searchable. Note, heavy indexing should not set this to true. Defaults + * to false. + */ + public UpdateRequest refresh(boolean refresh) { + this.refresh = refresh; + return this; + } + + public boolean refresh() { + return this.refresh; + } + /** * The replication type. */ @@ -316,6 +332,7 @@ public class UpdateRequest extends InstanceShardOperationRequest { if (in.readBoolean()) { percolate = in.readUTF(); } + refresh = in.readBoolean(); } @Override @@ -346,5 +363,6 @@ public class UpdateRequest extends InstanceShardOperationRequest { out.writeBoolean(true); out.writeUTF(percolate); } + out.writeBoolean(refresh); } } diff --git a/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java b/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java index e65d2bdc55c..9ddbf28f74e 100644 --- a/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java @@ -136,6 +136,16 @@ public class UpdateRequestBuilder extends BaseRequestBuildertrue. Defaults + * to false. + */ + public UpdateRequestBuilder setRefresh(boolean refresh) { + request.refresh(refresh); + return this; + } + /** * Sets the replication type. */ diff --git a/src/main/java/org/elasticsearch/rest/action/update/RestUpdateAction.java b/src/main/java/org/elasticsearch/rest/action/update/RestUpdateAction.java index 3e3eb366927..bf8bb01935c 100644 --- a/src/main/java/org/elasticsearch/rest/action/update/RestUpdateAction.java +++ b/src/main/java/org/elasticsearch/rest/action/update/RestUpdateAction.java @@ -57,6 +57,7 @@ public class RestUpdateAction extends BaseRestHandler { updateRequest.routing(request.param("routing")); updateRequest.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing updateRequest.timeout(request.paramAsTime("timeout", updateRequest.timeout())); + updateRequest.refresh(request.paramAsBoolean("refresh", updateRequest.refresh())); String replicationType = request.param("replication"); if (replicationType != null) { updateRequest.replicationType(ReplicationType.fromString(replicationType));