Skip to content

Commit 2d15cd8

Browse files
Adriano Ferreirakimchy
authored andcommitted
Another test for parsing "geo_distance" filter: 12mi and km
If an explicit unit is provided with "distance", the "unit" can be safely ignored, as it works as a fallback unit.
1 parent 8c8b7be commit 2d15cd8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,19 @@ private XContentIndexQueryParser queryParser() throws IOException {
13111311
assertThat(filter.distance(), closeTo(12, 0.00001));
13121312
}
13131313

1314+
@Test public void testGeoDistanceFilter12() throws IOException {
1315+
IndexQueryParser queryParser = queryParser();
1316+
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance12.json");
1317+
Query parsedQuery = queryParser.parse(query).query();
1318+
assertThat(parsedQuery, instanceOf(FilteredQuery.class));
1319+
FilteredQuery filteredQuery = (FilteredQuery) parsedQuery;
1320+
GeoDistanceFilter filter = (GeoDistanceFilter) filteredQuery.getFilter();
1321+
assertThat(filter.fieldName(), equalTo("location"));
1322+
assertThat(filter.lat(), closeTo(40, 0.00001));
1323+
assertThat(filter.lon(), closeTo(-70, 0.00001));
1324+
assertThat(filter.distance(), closeTo(12, 0.00001));
1325+
}
1326+
13141327
@Test public void testGeoBoundingBoxFilterNamed() throws IOException {
13151328
IndexQueryParser queryParser = queryParser();
13161329
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" : "12mi",
9+
"unit": "km",
10+
"person.location" : {
11+
"lat" : 40,
12+
"lon" : -70
13+
}
14+
}
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)