Skip to content

Commit efa60f7

Browse files
committed
Improve error detection in geo_filter parsing
Relates to elastic#5370
1 parent 5be5ea4 commit efa60f7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main/java/org/elasticsearch/index/query/GeoPolygonFilterParser.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
public class GeoPolygonFilterParser implements FilterParser {
5454

5555
public static final String NAME = "geo_polygon";
56-
public static final String POINTS = "points";
56+
public static final String POINTS = "points";
5757

5858
@Inject
5959
public GeoPolygonFilterParser() {
@@ -91,13 +91,15 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
9191
if (token == XContentParser.Token.FIELD_NAME) {
9292
currentFieldName = parser.currentName();
9393
} else if (token == XContentParser.Token.START_ARRAY) {
94-
if(POINTS.equals(currentFieldName)) {
95-
while((token = parser.nextToken()) != Token.END_ARRAY) {
94+
if (POINTS.equals(currentFieldName)) {
95+
while ((token = parser.nextToken()) != Token.END_ARRAY) {
9696
shell.add(GeoPoint.parse(parser));
9797
}
9898
} else {
9999
throw new QueryParsingException(parseContext.index(), "[geo_polygon] filter does not support [" + currentFieldName + "]");
100100
}
101+
} else {
102+
throw new QueryParsingException(parseContext.index(), "[geo_polygon] filter does not support token type [" + token.name() + "] under [" + currentFieldName + "]");
101103
}
102104
}
103105
} else if (token.isValue()) {
@@ -113,20 +115,22 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
113115
} else {
114116
throw new QueryParsingException(parseContext.index(), "[geo_polygon] filter does not support [" + currentFieldName + "]");
115117
}
118+
} else {
119+
throw new QueryParsingException(parseContext.index(), "[geo_polygon] unexpected token type [" + token.name() + "]");
116120
}
117121
}
118122

119123
if (shell.isEmpty()) {
120124
throw new QueryParsingException(parseContext.index(), "no points defined for geo_polygon filter");
121125
} else {
122-
if(shell.size() < 3) {
126+
if (shell.size() < 3) {
123127
throw new QueryParsingException(parseContext.index(), "to few points defined for geo_polygon filter");
124128
}
125129
GeoPoint start = shell.get(0);
126-
if(!start.equals(shell.get(shell.size()-1))) {
130+
if (!start.equals(shell.get(shell.size() - 1))) {
127131
shell.add(start);
128132
}
129-
if(shell.size() < 4) {
133+
if (shell.size() < 4) {
130134
throw new QueryParsingException(parseContext.index(), "to few points defined for geo_polygon filter");
131135
}
132136
}

0 commit comments

Comments
 (0)