Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that multi_search request hands over its context and headers to its corresponding search requests #7374

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/org/elasticsearch/action/search/SearchRequest.java
Expand Up @@ -94,6 +94,31 @@ public class SearchRequest extends ActionRequest<SearchRequest> implements Indic
public SearchRequest() {
}

/**
* Copy constructor that creates a new search 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 SearchRequest(SearchRequest searchRequest, ActionRequest originalRequest) {
super(originalRequest);
this.searchType = searchRequest.searchType;
this.indices = searchRequest.indices;
this.routing = searchRequest.routing;
this.preference = searchRequest.preference;
this.templateSource = searchRequest.templateSource;
this.templateSourceUnsafe = searchRequest.templateSourceUnsafe;
this.templateName = searchRequest.templateName;
this.templateType = searchRequest.templateType;
this.templateParams = searchRequest.templateParams;
this.source = searchRequest.source;
this.sourceUnsafe = searchRequest.sourceUnsafe;
this.extraSource = searchRequest.extraSource;
this.extraSourceUnsafe = searchRequest.extraSourceUnsafe;
this.queryCache = searchRequest.queryCache;
this.scroll = searchRequest.scroll;
this.types = searchRequest.types;
this.indicesOptions = searchRequest.indicesOptions;
}

/**
* Constructs a new search request starting from the provided request, meaning that it will
* inherit its headers and context
Expand Down
Expand Up @@ -23,16 +23,13 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AtomicArray;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.BaseTransportRequestHandler;
import org.elasticsearch.transport.TransportChannel;
import org.elasticsearch.transport.TransportService;

import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -61,7 +58,8 @@ protected void doExecute(final MultiSearchRequest request, final ActionListener<
final AtomicInteger counter = new AtomicInteger(responses.length());
for (int i = 0; i < responses.length(); i++) {
final int index = i;
searchAction.execute(request.requests().get(i), new ActionListener<SearchResponse>() {
SearchRequest searchRequest = new SearchRequest(request.requests().get(i), request);
searchAction.execute(searchRequest, new ActionListener<SearchResponse>() {
@Override
public void onResponse(SearchResponse searchResponse) {
responses.set(index, new MultiSearchResponse.Item(searchResponse, null));
Expand Down