diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java index 5559f890558..3324417f7c6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.query; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.SearchParseElement; +import org.elasticsearch.search.SearchParseException; import org.elasticsearch.search.internal.SearchContext; /** @@ -31,7 +32,11 @@ public class FromParseElement implements SearchParseElement { @Override public void parse(XContentParser parser, SearchContext context) throws Exception { XContentParser.Token token = parser.currentToken(); if (token.isValue()) { - context.from(parser.intValue()); + int from = parser.intValue(); + if (from < 0) { + throw new SearchParseException(context, "from is set to [" + from + "] and is expected to be higher or equal to 0"); + } + context.from(from); } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java index 2ec0ac26538..bd6433dc1cf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.query; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.SearchParseElement; +import org.elasticsearch.search.SearchParseException; import org.elasticsearch.search.internal.SearchContext; /** @@ -31,7 +32,11 @@ public class SizeParseElement implements SearchParseElement { @Override public void parse(XContentParser parser, SearchContext context) throws Exception { XContentParser.Token token = parser.currentToken(); if (token.isValue()) { - context.size(parser.intValue()); + int size = parser.intValue(); + if (size < 0) { + throw new SearchParseException(context, "size is set to [" + size + "] and is expected to be higher or equal to 0"); + } + context.size(size); } } } \ No newline at end of file