Repsect indices options on _msearch (#35887)
Today we don't respect the indices options when they are passed as request parameters to the `_msearch` endpoint. This is unintuitive and doesn't cause any errors. This changes uses the top-level indices options as the defaults for each sub search-request. Closes #35851
This commit is contained in:
parent
b078e2970c
commit
ca9b2b9931
|
@ -205,7 +205,7 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice
|
||||||
if (searchType != null) {
|
if (searchType != null) {
|
||||||
searchRequest.searchType(searchType);
|
searchRequest.searchType(searchType);
|
||||||
}
|
}
|
||||||
IndicesOptions defaultOptions = SearchRequest.DEFAULT_INDICES_OPTIONS;
|
IndicesOptions defaultOptions = searchRequest.indicesOptions();
|
||||||
// now parse the action
|
// now parse the action
|
||||||
if (nextMarker - from > 0) {
|
if (nextMarker - from > 0) {
|
||||||
try (InputStream stream = data.slice(from, nextMarker - from).streamInput();
|
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));
|
searchRequest.routing(nodeStringValue(value, null));
|
||||||
} else if ("allow_partial_search_results".equals(entry.getKey())) {
|
} else if ("allow_partial_search_results".equals(entry.getKey())) {
|
||||||
searchRequest.allowPartialSearchResults(nodeBooleanValue(value, null));
|
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);
|
defaultOptions = IndicesOptions.fromMap(source, defaultOptions);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,8 @@ public class RestMultiSearchAction extends BaseRestHandler {
|
||||||
*/
|
*/
|
||||||
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
|
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
|
||||||
MultiSearchRequest multiRequest = new MultiSearchRequest();
|
MultiSearchRequest multiRequest = new MultiSearchRequest();
|
||||||
|
IndicesOptions indicesOptions = IndicesOptions.fromRequest(restRequest, multiRequest.indicesOptions());
|
||||||
|
multiRequest.indicesOptions(indicesOptions);
|
||||||
if (restRequest.hasParam("max_concurrent_searches")) {
|
if (restRequest.hasParam("max_concurrent_searches")) {
|
||||||
multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));
|
multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.elasticsearch.test.rest.FakeRestRequest;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
@ -102,6 +103,21 @@ public class MultiSearchRequestTests extends ESTestCase {
|
||||||
assertThat(request.requests().get(0).types().length, equalTo(0));
|
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 {
|
public void testSimpleAdd2() throws Exception {
|
||||||
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/simple-msearch2.json");
|
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/simple-msearch2.json");
|
||||||
assertThat(request.requests().size(), equalTo(5));
|
assertThat(request.requests().size(), equalTo(5));
|
||||||
|
|
Loading…
Reference in New Issue