File tree Expand file tree Collapse file tree 3 files changed +38
-6
lines changed
main/java/org/elasticsearch/action/search
test/java/org/elasticsearch/search
rest-api-spec/src/main/resources/rest-api-spec/test/scroll Expand file tree Collapse file tree 3 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -161,17 +161,21 @@ public void writeTo(StreamOutput out) throws IOException {
161161 @ Override
162162 public ActionRequestValidationException validate () {
163163 ActionRequestValidationException validationException = null ;
164- if (source != null && source .trackTotalHits () == false && scroll () != null ) {
164+ final Scroll scroll = scroll ();
165+ if (source != null && source .trackTotalHits () == false && scroll != null ) {
165166 validationException =
166167 addValidationError ("disabling [track_total_hits] is not allowed in a scroll context" , validationException );
167168 }
168- if (source != null && source .from () > 0 && scroll () != null ) {
169+ if (source != null && source .from () > 0 && scroll != null ) {
169170 validationException =
170171 addValidationError ("using [from] is not allowed in a scroll context" , validationException );
171172 }
172- if (requestCache != null && requestCache && scroll () != null ) {
173+ if (requestCache != null && requestCache && scroll != null ) {
173174 validationException =
174- addValidationError ("[request_cache] cannot be used in a a scroll context" , validationException );
175+ addValidationError ("[request_cache] cannot be used in a scroll context" , validationException );
176+ }
177+ if (source != null && source .size () == 0 && scroll != null ) {
178+ validationException = addValidationError ("[size] cannot be [0] in a scroll context" , validationException );
175179 }
176180 return validationException ;
177181 }
Original file line number Diff line number Diff line change @@ -82,7 +82,6 @@ public void testIllegalArguments() {
8282 }
8383
8484 public void testValidate () throws IOException {
85-
8685 {
8786 // if scroll isn't set, validate should never add errors
8887 SearchRequest searchRequest = createSearchRequest ().source (new SearchSourceBuilder ());
@@ -114,6 +113,16 @@ public void testValidate() throws IOException {
114113 assertEquals (1 , validationErrors .validationErrors ().size ());
115114 assertEquals ("using [from] is not allowed in a scroll context" , validationErrors .validationErrors ().get (0 ));
116115 }
116+ {
117+ // scroll and `size` is `0`
118+ SearchRequest searchRequest = createSearchRequest ().source (new SearchSourceBuilder ().size (0 ));
119+ searchRequest .requestCache (false );
120+ searchRequest .scroll (new TimeValue (1000 ));
121+ ActionRequestValidationException validationErrors = searchRequest .validate ();
122+ assertNotNull (validationErrors );
123+ assertEquals (1 , validationErrors .validationErrors ().size ());
124+ assertEquals ("[size] cannot be [0] in a scroll context" , validationErrors .validationErrors ().get (0 ));
125+ }
117126 }
118127
119128 public void testEqualsAndHashcode () throws IOException {
Original file line number Diff line number Diff line change 206206 indices.create :
207207 index : test_scroll
208208 - do :
209- catch : /\[request_cache\] cannot be used in a a scroll context/
209+ catch : /\[request_cache\] cannot be used in a scroll context/
210210 search :
211211 index : test_scroll
212212 scroll : 1m
213213 request_cache : true
214214 body :
215215 query :
216216 match_all : {}
217+
218+ ---
219+ " Scroll with size 0 " :
220+ - skip :
221+ version : " - 6.99.99"
222+ reason : the error message has been added in v7.0.0
223+ - do :
224+ indices.create :
225+ index : test_scroll
226+ - do :
227+ catch : /\[size\] cannot be \[0\] in a scroll context/
228+ search :
229+ index : test_scroll
230+ scroll : 1m
231+ request_cache : true
232+ body :
233+ query :
234+ match_all : {}
235+ size : 0
You can’t perform that action at this time.
0 commit comments