Skip to content

Commit

Permalink
Async search: prevent users from overriding pre_filter_shard_size (#5…
Browse files Browse the repository at this point in the history
…4088)

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.
  • Loading branch information
javanna committed Mar 24, 2020
1 parent 3c67762 commit 6b457ab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions docs/reference/search/async-search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
number of new shard responses (`5` by default).
* `request_cache` defaults to `true`
* `pre_filter_shard_size` defaults to `1`: this is to enforce the execution of
a pre-filter roundtrip to retrieve statistics from each shard so that the ones
that surely don't hold any document matching the query get skipped.
* `pre_filter_shard_size` defaults to `1` and cannot be changed: this is to
enforce the execution of a pre-filter roundtrip to retrieve statistics from
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
supported value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public String getName() {
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
SubmitAsyncSearchRequest submit = new SubmitAsyncSearchRequest();
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 ->
parseSearchRequest(submit.getSearchRequest(), request, parser, setSize));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,13 @@ public void testValidateSuggestOnly() {
assertThat(exc.validationErrors().size(), equalTo(1));
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]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public boolean isCleanOnCompletion() {
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = request.validate();
if (request.scroll() != null) {
addValidationError("[scroll] queries are not supported", validationException);
validationException = addValidationError("[scroll] queries are not supported", validationException);
}
if (request.isSuggestOnly()) {
validationException = addValidationError("suggest-only queries are not supported", validationException);
Expand All @@ -141,6 +141,10 @@ public ActionRequestValidationException validate() {
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;
}
Expand Down

0 comments on commit 6b457ab

Please sign in to comment.