Skip to content

Commit 84b61d0

Browse files
authored
Scroll queries asking for rescore are considered invalid (#32918)
This PR changes our behavior from silently ignoring rescore in a scroll query to instead report to the user that such a query is invalid. Closes #31775
1 parent a381749 commit 84b61d0

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

docs/reference/migration/migrate_7_0/search.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ Setting `request_cache:true` on a query that creates a scroll (`scroll=1m`)
5454
has been deprecated in 6 and will now return a `400 - Bad request`.
5555
Scroll queries are not meant to be cached.
5656

57+
==== Scroll queries cannot use `rescore` anymore
58+
Including a rescore clause on a query that creates a scroll (`scroll=1m`) has
59+
been deprecated in 6.5 and will now return a `400 - Bad request`. Allowing
60+
rescore on scroll queries would break the scroll sort. In the 6.x line, the
61+
rescore clause was silently ignored (for scroll queries), and it was allowed in
62+
the 5.x line.
63+
5764
==== Term Suggesters supported distance algorithms
5865

5966
The following string distance algorithms were given additional names in 6.2 and

server/src/main/java/org/elasticsearch/action/search/SearchRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ public ActionRequestValidationException validate() {
184184
if (source != null && source.size() == 0 && scroll != null) {
185185
validationException = addValidationError("[size] cannot be [0] in a scroll context", validationException);
186186
}
187+
if (source != null && source.rescores() != null && source.rescores().isEmpty() == false && scroll != null) {
188+
validationException =
189+
addValidationError("using [rescore] is not allowed in a scroll context", validationException);
190+
}
187191
return validationException;
188192
}
189193

server/src/test/java/org/elasticsearch/search/SearchRequestTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import org.elasticsearch.common.io.stream.StreamInput;
2929
import org.elasticsearch.common.unit.TimeValue;
3030
import org.elasticsearch.common.util.ArrayUtils;
31+
import org.elasticsearch.index.query.QueryBuilders;
3132
import org.elasticsearch.search.builder.SearchSourceBuilder;
33+
import org.elasticsearch.search.rescore.QueryRescorerBuilder;
3234

3335
import java.io.IOException;
3436
import java.util.ArrayList;
@@ -123,6 +125,17 @@ public void testValidate() throws IOException {
123125
assertEquals(1, validationErrors.validationErrors().size());
124126
assertEquals("[size] cannot be [0] in a scroll context", validationErrors.validationErrors().get(0));
125127
}
128+
{
129+
// Rescore is not allowed on scroll requests
130+
SearchRequest searchRequest = createSearchRequest().source(new SearchSourceBuilder());
131+
searchRequest.source().addRescorer(new QueryRescorerBuilder(QueryBuilders.matchAllQuery()));
132+
searchRequest.requestCache(false);
133+
searchRequest.scroll(new TimeValue(1000));
134+
ActionRequestValidationException validationErrors = searchRequest.validate();
135+
assertNotNull(validationErrors);
136+
assertEquals(1, validationErrors.validationErrors().size());
137+
assertEquals("using [rescore] is not allowed in a scroll context", validationErrors.validationErrors().get(0));
138+
}
126139
}
127140

128141
public void testEqualsAndHashcode() throws IOException {

0 commit comments

Comments
 (0)