Skip to content

Commit 920e935

Browse files
Adriano Ferreirakimchy
authored andcommitted
Two tests for parsing "geo_distance" filter: distance/unit parameters
Those two are supposed to be equivalent: distance: 12, unit: "mi" vs distance: "12", unit: "mi" but they are not because of an underlying bug in the query parsing code, providing non-equivalent behavior whether a number or a string comes via JSON.
1 parent 63839d3 commit 920e935

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,32 @@ private XContentIndexQueryParser queryParser() throws IOException {
12201220
assertThat(filter.distance(), closeTo(12, 0.00001));
12211221
}
12221222

1223+
@Test public void testGeoDistanceFilter5() throws IOException {
1224+
IndexQueryParser queryParser = queryParser();
1225+
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance5.json");
1226+
Query parsedQuery = queryParser.parse(query).query();
1227+
assertThat(parsedQuery, instanceOf(FilteredQuery.class));
1228+
FilteredQuery filteredQuery = (FilteredQuery) parsedQuery;
1229+
GeoDistanceFilter filter = (GeoDistanceFilter) filteredQuery.getFilter();
1230+
assertThat(filter.fieldName(), equalTo("location"));
1231+
assertThat(filter.lat(), closeTo(40, 0.00001));
1232+
assertThat(filter.lon(), closeTo(-70, 0.00001));
1233+
assertThat(filter.distance(), closeTo(12, 0.00001));
1234+
}
1235+
1236+
@Test public void testGeoDistanceFilter6() throws IOException {
1237+
IndexQueryParser queryParser = queryParser();
1238+
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance6.json");
1239+
Query parsedQuery = queryParser.parse(query).query();
1240+
assertThat(parsedQuery, instanceOf(FilteredQuery.class));
1241+
FilteredQuery filteredQuery = (FilteredQuery) parsedQuery;
1242+
GeoDistanceFilter filter = (GeoDistanceFilter) filteredQuery.getFilter();
1243+
assertThat(filter.fieldName(), equalTo("location"));
1244+
assertThat(filter.lat(), closeTo(40, 0.00001));
1245+
assertThat(filter.lon(), closeTo(-70, 0.00001));
1246+
assertThat(filter.distance(), closeTo(12, 0.00001));
1247+
}
1248+
12231249
@Test public void testGeoBoundingBoxFilterNamed() throws IOException {
12241250
IndexQueryParser queryParser = queryParser();
12251251
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox-named.json");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"filtered" : {
3+
"query" : {
4+
"match_all" : {}
5+
},
6+
"filter" : {
7+
"geo_distance" : {
8+
"distance" : 12,
9+
"unit": "mi",
10+
"person.location" : {
11+
"lat" : 40,
12+
"lon" : -70
13+
}
14+
}
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"filtered" : {
3+
"query" : {
4+
"match_all" : {}
5+
},
6+
"filter" : {
7+
"geo_distance" : {
8+
"distance" : "12",
9+
"unit": "mi",
10+
"person.location" : {
11+
"lat" : 40,
12+
"lon" : -70
13+
}
14+
}
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)