Get Action: Allow to pass refresh forcing getting latest, closes #488.

This commit is contained in:
kimchy 2010-11-07 23:50:48 +02:00
parent e51523385d
commit c095d72439
5 changed files with 32 additions and 0 deletions

View File

@ -52,6 +52,7 @@
<w>formatters</w>
<w>frac</w>
<w>freqs</w>
<w>func</w>
<w>geohash</w>
<w>guice</w>
<w>hadoop</w>

View File

@ -42,6 +42,8 @@ public class GetRequest extends SingleOperationRequest {
private String[] fields;
private boolean refresh = false;
GetRequest() {
}
@ -115,6 +117,20 @@ public class GetRequest extends SingleOperationRequest {
return this.fields;
}
/**
* Should a refresh be executed before this get operation causing the operation to
* return the latest value. Note, heavy get should not set this to <tt>true</tt>. Defaults
* to <tt>false</tt>.
*/
public GetRequest refresh(boolean refresh) {
this.refresh = refresh;
return this;
}
public boolean refresh() {
return this.refresh;
}
/**
* Should the listener be called on a separate thread if needed.
*/

View File

@ -78,6 +78,10 @@ public class TransportGetAction extends TransportSingleOperationAction<GetReques
throw new DocumentMapperNotFoundException("No mapper found for type [" + request.type() + "]");
}
if (request.refresh()) {
indexShard.refresh(new Engine.Refresh(false));
}
Engine.Searcher searcher = indexShard.searcher();
boolean exists = false;
byte[] source = null;

View File

@ -80,6 +80,16 @@ public class GetRequestBuilder extends BaseRequestBuilder<GetRequest, GetRespons
return this;
}
/**
* Should a refresh be executed before this get operation causing the operation to
* return the latest value. Note, heavy get should not set this to <tt>true</tt>. Defaults
* to <tt>false</tt>.
*/
public GetRequestBuilder setRefresh(boolean refresh) {
request.refresh(refresh);
return this;
}
/**
* Should the listener be called on a separate thread if needed.
*/

View File

@ -57,6 +57,7 @@ public class RestGetAction extends BaseRestHandler {
getRequest.listenerThreaded(false);
// if we have a local operation, execute it on a thread since we don't spawn
getRequest.operationThreaded(true);
getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
getRequest.routing(request.param("routing"));