diff --git a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java index f75ea37f854..414062c0cd2 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java @@ -372,14 +372,14 @@ public class FieldSortBuilder extends SortBuilder { } else if ("desc".equals(sortOrder)) { order = SortOrder.DESC; } else { - throw new IllegalStateException("Sort order " + sortOrder + " not supported."); + throw new ParsingException(parser.getTokenLocation(), "Sort order [{}] not supported.", sortOrder); } } else if (context.parseFieldMatcher().match(currentFieldName, SORT_MODE)) { sortMode = SortMode.fromString(parser.text()); } else if (context.parseFieldMatcher().match(currentFieldName, UNMAPPED_TYPE)) { unmappedType = parser.text(); } else { - throw new IllegalArgumentException("Option " + currentFieldName + " not supported."); + throw new ParsingException(parser.getTokenLocation(), "Option [{}] not supported.", currentFieldName); } } } diff --git a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java index 4712799c658..c6a63d5f085 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java @@ -29,6 +29,7 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.Version; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoDistance.FixedSourceDistance; import org.elasticsearch.common.geo.GeoPoint; @@ -72,6 +73,7 @@ public class GeoDistanceSortBuilder extends SortBuilder public static final ParseField SORTMODE_FIELD = new ParseField("mode", "sort_mode"); public static final ParseField NESTED_PATH_FIELD = new ParseField("nested_path"); public static final ParseField NESTED_FILTER_FIELD = new ParseField("nested_filter"); + public static final ParseField REVERSE_FORBIDDEN = new ParseField("reverse"); public static final GeoDistanceSortBuilder PROTOTYPE = new GeoDistanceSortBuilder("_na_", -1, -1); @@ -465,6 +467,14 @@ public class GeoDistanceSortBuilder extends SortBuilder sortMode = SortMode.fromString(parser.text()); } else if (parseFieldMatcher.match(currentName, NESTED_PATH_FIELD)) { nestedPath = parser.text(); + } else if (parseFieldMatcher.match(currentName, REVERSE_FORBIDDEN)) { + // explicitly filter for reverse in json: used to be a valid sort option, forbidden now, + // if not filtered here it will be treated as a reference to a field in the index with + // geo coordinates given as geohash string + throw new ParsingException( + parser.getTokenLocation(), + "Sort option [{}] no longer supported.", + REVERSE_FORBIDDEN.getPreferredName()); } else { GeoPoint point = new GeoPoint(); point.resetFromString(parser.text()); diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java index 9124540f881..c222634ca0c 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java @@ -41,6 +41,7 @@ public class ScoreSortBuilder extends SortBuilder { public static final String NAME = "_score"; public static final ScoreSortBuilder PROTOTYPE = new ScoreSortBuilder(); public static final ParseField ORDER_FIELD = new ParseField("order"); + private static final ParseField REVERSE_FORBIDDEN = new ParseField("reverse"); private static final SortField SORT_SCORE = new SortField(null, SortField.Type.SCORE); private static final SortField SORT_SCORE_REVERSE = new SortField(null, SortField.Type.SCORE, true); diff --git a/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java index 2c1a4a65c7b..f28ec8797c2 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java @@ -20,6 +20,12 @@ x * Licensed to Elasticsearch under one or more contributor package org.elasticsearch.search.sort; import org.apache.lucene.search.SortField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParsingException; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; import java.io.IOException; @@ -103,4 +109,26 @@ public class FieldSortBuilderTests extends AbstractSortTestCase