diff options
author | Colin Goodheart-Smithe <colings86@users.noreply.github.com> | 2017-07-04 10:51:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-04 10:51:38 +0100 |
commit | 43efcffcc217f5e49ed15593bc3156c2b4db1c73 (patch) | |
tree | 56cbb7b9c5a23e0754cfbb9a0ac60fffbff2dd20 /core/src/main/java | |
parent | 1c63c823b0e4c07d4ba0e4767840f68162b7b4b8 (diff) |
Adds check for negative search request size (#25397)
* Adds check for negative search request size
This change adds a check to `SearchSourceBuilder` to throw and exception if the size set on it is set to a negative value.
Closes #22530
* fix error in reindex
* update re-index tests
* Addresses review comment
* Fixed tests
* Added random negative size test
* Fixes test
Diffstat (limited to 'core/src/main/java')
-rw-r--r-- | core/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java | 10 | ||||
-rw-r--r-- | core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java | 3 |
2 files changed, 11 insertions, 2 deletions
diff --git a/core/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java b/core/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java index 5bfae5fde9..9f10304622 100644 --- a/core/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java +++ b/core/src/main/java/org/elasticsearch/index/reindex/AbstractBulkByScrollRequest.java @@ -171,6 +171,9 @@ public abstract class AbstractBulkByScrollRequest<Self extends AbstractBulkByScr * documents. */ public Self setSize(int size) { + if (size < 0) { + throw new IllegalArgumentException("[size] parameter cannot be negative, found [" + size + "]"); + } this.size = size; return self(); } @@ -367,10 +370,13 @@ public abstract class AbstractBulkByScrollRequest<Self extends AbstractBulkByScr .setShouldStoreResult(false) // Split requests per second between all slices .setRequestsPerSecond(requestsPerSecond / slices) - // Size is split between workers. This means the size might round down! - .setSize(size == SIZE_ALL_MATCHES ? SIZE_ALL_MATCHES : size / slices) // Sub requests don't have workers .setSlices(1); + if (size != -1) { + // Size is split between workers. This means the size might round + // down! + request.setSize(size == SIZE_ALL_MATCHES ? SIZE_ALL_MATCHES : size / slices); + } // Set the parent task so this task is cancelled if we cancel the parent request.setParentTask(slicingTask); // TODO It'd be nice not to refresh on every slice. Instead we should refresh after the sub requests finish. diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 91edc29160..537635895e 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -345,6 +345,9 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ * The number of search hits to return. Defaults to <tt>10</tt>. */ public SearchSourceBuilder size(int size) { + if (size < 0) { + throw new IllegalArgumentException("[size] parameter cannot be negative, found [" + size + "]"); + } this.size = size; return this; } |