Improve error detection in geo_filter parsing

Relates to #5370
This commit is contained in:
Boaz Leskes 2014-03-09 08:53:29 +01:00
parent fbb8c0fafa
commit bb63b3fa61
7 changed files with 127 additions and 8 deletions

View File

@ -98,6 +98,8 @@ public class GeoPolygonFilterParser implements FilterParser {
} else {
throw new QueryParsingException(parseContext.index(), "[geo_polygon] filter does not support [" + currentFieldName + "]");
}
} else {
throw new QueryParsingException(parseContext.index(), "[geo_polygon] filter does not support token type [" + token.name() + "] under [" + currentFieldName + "]");
}
}
} else if (token.isValue()) {
@ -113,6 +115,8 @@ public class GeoPolygonFilterParser implements FilterParser {
} else {
throw new QueryParsingException(parseContext.index(), "[geo_polygon] filter does not support [" + currentFieldName + "]");
}
} else {
throw new QueryParsingException(parseContext.index(), "[geo_polygon] unexpected token type [" + token.name() + "]");
}
}

View File

@ -2038,6 +2038,29 @@ public class SimpleIndexQueryParserTests extends ElasticsearchTestCase {
assertThat(filter.points()[2].lon(), closeTo(-90, 0.00001));
}
@Test
public void testGeoPolygonFilterParsingExceptions() throws IOException {
String[] brokenFiles = new String[]{
"/org/elasticsearch/index/query/geo_polygon_exception_1.json",
"/org/elasticsearch/index/query/geo_polygon_exception_2.json",
"/org/elasticsearch/index/query/geo_polygon_exception_3.json",
"/org/elasticsearch/index/query/geo_polygon_exception_4.json",
"/org/elasticsearch/index/query/geo_polygon_exception_5.json"
};
for (String brokenFile : brokenFiles) {
IndexQueryParserService queryParser = queryParser();
String query = copyToStringFromClasspath(brokenFile);
try {
queryParser.parse(query).query();
fail("parsing a broken geo_polygon filter didn't fail as expected while parsing: " + brokenFile);
} catch (QueryParsingException e) {
// success!
}
}
}
@Test
public void testGeoPolygonFilter1() throws IOException {
IndexQueryParserService queryParser = queryParser();

View File

@ -0,0 +1,20 @@
{
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"location": {
"points": {
"points": [
[-70, 40],
[-80, 30],
[-90, 20]
]
}
}
}
}
}
}

View File

@ -0,0 +1,22 @@
{
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"location": {
"points": [
[-70, 40],
[-80, 30],
[-90, 20]
],
"something_else": {
}
}
}
}
}
}

View File

@ -0,0 +1,12 @@
{
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"location": ["WRONG"]
}
}
}
}

View File

@ -0,0 +1,19 @@
{
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"location": {
"points": [
[-70, 40],
[-80, 30],
[-90, 20]
]
},
"bla": true
}
}
}
}

View File

@ -0,0 +1,19 @@
{
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_polygon": {
"location": {
"points": [
[-70, 40],
[-80, 30],
[-90, 20]
]
},
"bla": ["array"]
}
}
}
}