diff --git a/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java b/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java index 0cff8aadb52..165cc1f1537 100644 --- a/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java +++ b/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java @@ -205,7 +205,7 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice if (searchType != null) { searchRequest.searchType(searchType); } - IndicesOptions defaultOptions = SearchRequest.DEFAULT_INDICES_OPTIONS; + IndicesOptions defaultOptions = searchRequest.indicesOptions(); // now parse the action if (nextMarker - from > 0) { try (InputStream stream = data.slice(from, nextMarker - from).streamInput(); @@ -230,7 +230,10 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice searchRequest.routing(nodeStringValue(value, null)); } else if ("allow_partial_search_results".equals(entry.getKey())) { searchRequest.allowPartialSearchResults(nodeBooleanValue(value, null)); + } else { + // TODO we should not be lenient here and fail if there is any unknown key in the source map } + } defaultOptions = IndicesOptions.fromMap(source, defaultOptions); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index d3a45fa727b..30a97c0fdbd 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -86,6 +86,8 @@ public class RestMultiSearchAction extends BaseRestHandler { */ public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException { MultiSearchRequest multiRequest = new MultiSearchRequest(); + IndicesOptions indicesOptions = IndicesOptions.fromRequest(restRequest, multiRequest.indicesOptions()); + multiRequest.indicesOptions(indicesOptions); if (restRequest.hasParam("max_concurrent_searches")) { multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0)); } diff --git a/server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java b/server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java index 8c871d54530..c02e3e17d58 100644 --- a/server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java @@ -41,6 +41,7 @@ import org.elasticsearch.test.rest.FakeRestRequest; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import static java.util.Collections.singletonList; @@ -102,6 +103,21 @@ public class MultiSearchRequestTests extends ESTestCase { assertThat(request.requests().get(0).types().length, equalTo(0)); } + public void testDefaultIndicesOptions() throws IOException { + final String requestContent = "{\"index\":\"test\", \"expand_wildcards\" : \"open,closed\"}}\r\n" + + "{\"query\" : {\"match_all\" :{}}}\r\n"; + FakeRestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withContent(new BytesArray(requestContent), XContentType.JSON) + .withParams(Collections.singletonMap("ignore_unavailable", "true")) + .build(); + MultiSearchRequest request = RestMultiSearchAction.parseRequest(restRequest, true); + assertThat(request.requests().size(), equalTo(1)); + assertThat(request.requests().get(0).indices()[0], equalTo("test")); + assertThat(request.requests().get(0).indicesOptions(), + equalTo(IndicesOptions.fromOptions(true, true, true, true, SearchRequest.DEFAULT_INDICES_OPTIONS))); + assertThat(request.requests().get(0).types().length, equalTo(0)); + } + public void testSimpleAdd2() throws Exception { MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/simple-msearch2.json"); assertThat(request.requests().size(), equalTo(5));