Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll queries asking for rescore are considered invalid #32918

Merged
merged 12 commits into from
Aug 28, 2018
6 changes: 6 additions & 0 deletions docs/reference/migration/migrate_7_0/search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ Setting `request_cache:true` on a query that creates a scroll (`scroll=1m`)
has been deprecated in 6 and will now return a `400 - Bad request`.
Scroll queries are not meant to be cached.

==== Scroll queries cannot use `rescore` anymore
Including a rescore clause on a query that creates a scroll (`scroll=1m`)
has been deprecated in 6 and will now return a `400 - Bad request`. Allowing
rescore on scroll queries would break the scroll sort. In 6, the rescore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe replace 6 with previous versions (only this second occurrence)? also when you mention the version can you specify also the minor version that is was deprecated in ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this language a bit. I want to be careful here, because according to the original ticket, this was allowed at some time in the 5.x line. It's not clear to me when exactly we stopped supporting rescoring scroll queries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

clause was silently ignored.

==== Term Suggesters supported distance algorithms

The following string distance algorithms were given additional names in 6.2 and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public ActionRequestValidationException validate() {
if (source != null && source.size() == 0 && scroll != null) {
validationException = addValidationError("[size] cannot be [0] in a scroll context", validationException);
}
if (source != null && source.rescores() != null && source.rescores().isEmpty() == false && scroll != null) {
validationException =
addValidationError("using [rescore] is not allowed in a scroll context", validationException);
}
return validationException;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.ArrayUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.rescore.RescorerBuilder;
import org.elasticsearch.search.rescore.RescoreContext;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -123,6 +129,17 @@ public void testValidate() throws IOException {
assertEquals(1, validationErrors.validationErrors().size());
assertEquals("[size] cannot be [0] in a scroll context", validationErrors.validationErrors().get(0));
}
{
// Rescore is not allowed on scroll requests
SearchRequest searchRequest = createSearchRequest().source(new SearchSourceBuilder());
searchRequest.source().addRescorer(new NoOpRescorerBuilder());
searchRequest.requestCache(false);
searchRequest.scroll(new TimeValue(1000));
ActionRequestValidationException validationErrors = searchRequest.validate();
assertNotNull(validationErrors);
assertEquals(1, validationErrors.validationErrors().size());
assertEquals("using [rescore] is not allowed in a scroll context", validationErrors.validationErrors().get(0));
}
}

public void testEqualsAndHashcode() throws IOException {
Expand Down Expand Up @@ -164,4 +181,33 @@ private static SearchRequest copyRequest(SearchRequest searchRequest) throws IOE
}
return result;
}

private static class NoOpRescorerBuilder extends RescorerBuilder<NoOpRescorerBuilder> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had not looked closely now I see why you were using mockito before :) I don't mind if you prefer to go back to it, I am happy either way

NoOpRescorerBuilder() throws IOException {
}

@Override
public String getWriteableName() {
return "test";
}

@Override
public RescorerBuilder<NoOpRescorerBuilder> rewrite(QueryRewriteContext ctx) throws IOException {
return this;
}

@Override
protected void doWriteTo(StreamOutput out) throws IOException {
}

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
}

@Override
public RescoreContext innerBuildContext(int windowSize, QueryShardContext context) throws IOException {
return null;
}
}

}