Reindex and friends fail nicely when max_docs < slices (#54901) (#57348)

When the parameter `max_docs` is less than `slices` in update_by_query,
delete_by_query or reindex API, `max_docs ` is set to 0 and we throw an
action_request_validation_exception with confused error message:
"maxDocs should be greater than 0...".
This change checks that whether `max_docs` is less than `slices` and
throw an illegal_argument_exception with clear message.

Relates to #52786.

Co-authored-by: bellengao <gbl_long@163.com>
This commit is contained in:
Henning Andersen 2020-05-29 14:30:14 +02:00 committed by GitHub
parent d8928b3f48
commit 8427d677e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 0 deletions

View File

@ -87,6 +87,27 @@
query:
match_all: {}
---
"max_docs shoule be greater than slices":
- skip:
version: " - 7.2.99"
reason: "max_docs introduced in 7.3.0"
- do:
index:
index: test
id: 1
body: { "text": "test" }
- do:
catch: /\[max_docs\] should be >= \[slices\]/
delete_by_query:
index: test
max_docs: 1
slices: 2
body:
query:
match_all: {}
---
"invalid scroll_size fails":
- do:

View File

@ -132,6 +132,28 @@
index: dest
max_docs: -4
---
"max_docs shoule be greater than slices":
- skip:
version: " - 7.2.99"
reason: "max_docs introduced in 7.3.0"
- do:
index:
index: test
id: 1
body: { "text": "test" }
- do:
catch: /\[max_docs\] should be >= \[slices\]/
reindex:
max_docs: 1
slices: 2
body:
source:
index: test
dest:
index: dest
---
"invalid max_docs in URL fails":
- skip:

View File

@ -101,6 +101,24 @@
query:
match_all: {}
---
"max_docs shoule be greater than slices":
- skip:
version: " - 7.2.99"
reason: "max_docs introduced in 7.3.0"
- do:
index:
index: test
id: 1
body: { "text": "test" }
- do:
catch: /\[max_docs\] should be >= \[slices\]/
update_by_query:
index: test
max_docs: 1
slices: 2
---
"invalid scroll_size fails":
- do:

View File

@ -214,6 +214,9 @@ public abstract class AbstractBulkByScrollRequest<Self extends AbstractBulkByScr
if (maxDocs < 0) {
throw new IllegalArgumentException("[max_docs] parameter cannot be negative, found [" + maxDocs + "]");
}
if (maxDocs < slices) {
throw new IllegalArgumentException("[max_docs] should be >= [slices]");
}
this.maxDocs = maxDocs;
return self();
}