Async search: prevent users from overriding pre_filter_shard_size (#54088)
Submit async search forces pre_filter_shard_size for the underlying search that it creates. With this commit we also prevent users from overriding such default as part of request validation.
This commit is contained in:
parent
3c67762f1b
commit
6b457abbd3
|
@ -109,9 +109,10 @@ become available, which happens whenever shard results are reduced. A partial
|
||||||
reduction is performed every time the coordinating node has received a certain
|
reduction is performed every time the coordinating node has received a certain
|
||||||
number of new shard responses (`5` by default).
|
number of new shard responses (`5` by default).
|
||||||
* `request_cache` defaults to `true`
|
* `request_cache` defaults to `true`
|
||||||
* `pre_filter_shard_size` defaults to `1`: this is to enforce the execution of
|
* `pre_filter_shard_size` defaults to `1` and cannot be changed: this is to
|
||||||
a pre-filter roundtrip to retrieve statistics from each shard so that the ones
|
enforce the execution of a pre-filter roundtrip to retrieve statistics from
|
||||||
that surely don't hold any document matching the query get skipped.
|
each shard so that the ones that surely don't hold any document matching the
|
||||||
|
query get skipped.
|
||||||
* `ccs_minimize_roundtrips` defaults to `false`, which is also the only
|
* `ccs_minimize_roundtrips` defaults to `false`, which is also the only
|
||||||
supported value
|
supported value
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,9 @@ public final class RestSubmitAsyncSearchAction extends BaseRestHandler {
|
||||||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
SubmitAsyncSearchRequest submit = new SubmitAsyncSearchRequest();
|
SubmitAsyncSearchRequest submit = new SubmitAsyncSearchRequest();
|
||||||
IntConsumer setSize = size -> submit.getSearchRequest().source().size(size);
|
IntConsumer setSize = size -> submit.getSearchRequest().source().size(size);
|
||||||
|
//for simplicity, we share parsing with ordinary search. That means a couple of unsupported parameters, like scroll,
|
||||||
|
// pre_filter_shard_size and ccs_minimize_roundtrips get set to the search request although the REST spec don't list
|
||||||
|
//them as supported. We rely on SubmitAsyncSearchRequest#validate to fail in case they are set.
|
||||||
request.withContentOrSourceParamParserOrNull(parser ->
|
request.withContentOrSourceParamParserOrNull(parser ->
|
||||||
parseSearchRequest(submit.getSearchRequest(), request, parser, setSize));
|
parseSearchRequest(submit.getSearchRequest(), request, parser, setSize));
|
||||||
|
|
||||||
|
|
|
@ -109,4 +109,13 @@ public class SubmitAsyncSearchRequestTests extends AbstractWireSerializingTransf
|
||||||
assertThat(exc.validationErrors().size(), equalTo(1));
|
assertThat(exc.validationErrors().size(), equalTo(1));
|
||||||
assertThat(exc.validationErrors().get(0), containsString("suggest"));
|
assertThat(exc.validationErrors().get(0), containsString("suggest"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testValidatePreFilterShardSize() {
|
||||||
|
SubmitAsyncSearchRequest req = new SubmitAsyncSearchRequest();
|
||||||
|
req.getSearchRequest().setPreFilterShardSize(randomIntBetween(2, Integer.MAX_VALUE));
|
||||||
|
ActionRequestValidationException exc = req.validate();
|
||||||
|
assertNotNull(exc);
|
||||||
|
assertThat(exc.validationErrors().size(), equalTo(1));
|
||||||
|
assertThat(exc.validationErrors().get(0), containsString("[pre_filter_shard_size]"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class SubmitAsyncSearchRequest extends ActionRequest {
|
||||||
public ActionRequestValidationException validate() {
|
public ActionRequestValidationException validate() {
|
||||||
ActionRequestValidationException validationException = request.validate();
|
ActionRequestValidationException validationException = request.validate();
|
||||||
if (request.scroll() != null) {
|
if (request.scroll() != null) {
|
||||||
addValidationError("[scroll] queries are not supported", validationException);
|
validationException = addValidationError("[scroll] queries are not supported", validationException);
|
||||||
}
|
}
|
||||||
if (request.isSuggestOnly()) {
|
if (request.isSuggestOnly()) {
|
||||||
validationException = addValidationError("suggest-only queries are not supported", validationException);
|
validationException = addValidationError("suggest-only queries are not supported", validationException);
|
||||||
|
@ -141,6 +141,10 @@ public class SubmitAsyncSearchRequest extends ActionRequest {
|
||||||
validationException =
|
validationException =
|
||||||
addValidationError("[ccs_minimize_roundtrips] is not supported on async search queries", validationException);
|
addValidationError("[ccs_minimize_roundtrips] is not supported on async search queries", validationException);
|
||||||
}
|
}
|
||||||
|
if (request.getPreFilterShardSize() == null || request.getPreFilterShardSize() != 1) {
|
||||||
|
validationException =
|
||||||
|
addValidationError("[pre_filter_shard_size] cannot be changed for async search queries", validationException);
|
||||||
|
}
|
||||||
|
|
||||||
return validationException;
|
return validationException;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue