Internal: get request while percolating existing documents to keep around headers and context of the original percolate request
Closes #7333
This commit is contained in:
parent
b1f532eb85
commit
8458138b8c
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.action.get;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.ValidateActions;
|
||||
import org.elasticsearch.action.support.single.shard.SingleShardOperationRequest;
|
||||
|
@ -66,6 +67,26 @@ public class GetRequest extends SingleShardOperationRequest<GetRequest> {
|
|||
type = "_all";
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor that creates a new get request that is a copy of the one provided as an argument.
|
||||
* The new request will inherit though headers and context from the original request that caused it.
|
||||
*/
|
||||
public GetRequest(GetRequest getRequest, ActionRequest originalRequest) {
|
||||
super(originalRequest);
|
||||
this.index = getRequest.index;
|
||||
this.type = getRequest.type;
|
||||
this.id = getRequest.id;
|
||||
this.routing = getRequest.routing;
|
||||
this.preference = getRequest.preference;
|
||||
this.fields = getRequest.fields;
|
||||
this.fetchSourceContext = getRequest.fetchSourceContext;
|
||||
this.refresh = getRequest.refresh;
|
||||
this.realtime = getRequest.realtime;
|
||||
this.version = getRequest.version;
|
||||
this.versionType = getRequest.versionType;
|
||||
this.ignoreErrorsOnGeneratedFields = getRequest.ignoreErrorsOnGeneratedFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new get request against the specified index. The {@link #type(String)} and {@link #id(String)}
|
||||
* must be set.
|
||||
|
|
|
@ -246,8 +246,6 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
|
|||
}
|
||||
}
|
||||
|
||||
private boolean listenerThreaded = false;
|
||||
|
||||
String preference;
|
||||
Boolean realtime;
|
||||
boolean refresh;
|
||||
|
@ -255,6 +253,18 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
|
|||
|
||||
List<Item> items = new ArrayList<>();
|
||||
|
||||
public MultiGetRequest() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a multi get request caused by some other request, which is provided as an
|
||||
* argument so that its headers and context can be copied to the new request
|
||||
*/
|
||||
public MultiGetRequest(ActionRequest request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP
|
|||
}
|
||||
|
||||
if (!existingDocsRequests.isEmpty()) {
|
||||
final MultiGetRequest multiGetRequest = new MultiGetRequest();
|
||||
final MultiGetRequest multiGetRequest = new MultiGetRequest(request);
|
||||
for (GetRequest getRequest : existingDocsRequests) {
|
||||
multiGetRequest.add(
|
||||
new MultiGetRequest.Item(getRequest.index(), getRequest.type(), getRequest.id())
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.action.percolate;
|
|||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.get.TransportGetAction;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
|
@ -70,7 +71,9 @@ public class TransportPercolateAction extends TransportBroadcastOperationAction<
|
|||
protected void doExecute(final PercolateRequest request, final ActionListener<PercolateResponse> listener) {
|
||||
request.startTime = System.currentTimeMillis();
|
||||
if (request.getRequest() != null) {
|
||||
getAction.execute(request.getRequest(), new ActionListener<GetResponse>() {
|
||||
//create a new get request to make sure it has the same headers and context as the original percolate request
|
||||
GetRequest getRequest = new GetRequest(request.getRequest(), request);
|
||||
getAction.execute(getRequest, new ActionListener<GetResponse>() {
|
||||
@Override
|
||||
public void onResponse(GetResponse getResponse) {
|
||||
if (!getResponse.isExists()) {
|
||||
|
|
|
@ -43,6 +43,10 @@ public abstract class SingleShardOperationRequest<T extends SingleShardOperation
|
|||
protected SingleShardOperationRequest() {
|
||||
}
|
||||
|
||||
protected SingleShardOperationRequest(ActionRequest request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
public SingleShardOperationRequest(String index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue