From f956920acc866062b823fd66d86c59919631f752 Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 21 Aug 2014 14:40:35 +0200 Subject: [PATCH] Internal: make sure that multi_search request hands over its context and headers to its corresponding search requests Closes #7374 --- .../action/search/SearchRequest.java | 25 +++++++++++++++++++ .../search/TransportMultiSearchAction.java | 6 ++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/src/main/java/org/elasticsearch/action/search/SearchRequest.java index 2b17347b4a8..28a4e1e6961 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -94,6 +94,31 @@ public class SearchRequest extends ActionRequest 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 diff --git a/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java b/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java index b5ce0f6d0c1..a580c818468 100644 --- a/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java +++ b/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.ExceptionsHelper; 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; @@ -31,8 +30,6 @@ 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; @@ -61,7 +58,8 @@ public class TransportMultiSearchAction extends HandledTransportAction() { + SearchRequest searchRequest = new SearchRequest(request.requests().get(i), request); + searchAction.execute(searchRequest, new ActionListener() { @Override public void onResponse(SearchResponse searchResponse) { responses.set(index, new MultiSearchResponse.Item(searchResponse, null));