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.
This commit is contained in:
parent
14703aa1be
commit
0660a2912e
|
@ -1220,6 +1220,32 @@ public class SimpleIndexQueryParserTests {
|
|||
assertThat(filter.distance(), closeTo(12, 0.00001));
|
||||
}
|
||||
|
||||
@Test public void testGeoDistanceFilter5() throws IOException {
|
||||
IndexQueryParser queryParser = queryParser();
|
||||
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance5.json");
|
||||
Query parsedQuery = queryParser.parse(query).query();
|
||||
assertThat(parsedQuery, instanceOf(FilteredQuery.class));
|
||||
FilteredQuery filteredQuery = (FilteredQuery) parsedQuery;
|
||||
GeoDistanceFilter filter = (GeoDistanceFilter) filteredQuery.getFilter();
|
||||
assertThat(filter.fieldName(), equalTo("location"));
|
||||
assertThat(filter.lat(), closeTo(40, 0.00001));
|
||||
assertThat(filter.lon(), closeTo(-70, 0.00001));
|
||||
assertThat(filter.distance(), closeTo(12, 0.00001));
|
||||
}
|
||||
|
||||
@Test public void testGeoDistanceFilter6() throws IOException {
|
||||
IndexQueryParser queryParser = queryParser();
|
||||
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance6.json");
|
||||
Query parsedQuery = queryParser.parse(query).query();
|
||||
assertThat(parsedQuery, instanceOf(FilteredQuery.class));
|
||||
FilteredQuery filteredQuery = (FilteredQuery) parsedQuery;
|
||||
GeoDistanceFilter filter = (GeoDistanceFilter) filteredQuery.getFilter();
|
||||
assertThat(filter.fieldName(), equalTo("location"));
|
||||
assertThat(filter.lat(), closeTo(40, 0.00001));
|
||||
assertThat(filter.lon(), closeTo(-70, 0.00001));
|
||||
assertThat(filter.distance(), closeTo(12, 0.00001));
|
||||
}
|
||||
|
||||
@Test public void testGeoBoundingBoxFilterNamed() throws IOException {
|
||||
IndexQueryParser queryParser = queryParser();
|
||||
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox-named.json");
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"filtered" : {
|
||||
"query" : {
|
||||
"match_all" : {}
|
||||
},
|
||||
"filter" : {
|
||||
"geo_distance" : {
|
||||
"distance" : 12,
|
||||
"unit": "mi",
|
||||
"person.location" : {
|
||||
"lat" : 40,
|
||||
"lon" : -70
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"filtered" : {
|
||||
"query" : {
|
||||
"match_all" : {}
|
||||
},
|
||||
"filter" : {
|
||||
"geo_distance" : {
|
||||
"distance" : "12",
|
||||
"unit": "mi",
|
||||
"person.location" : {
|
||||
"lat" : 40,
|
||||
"lon" : -70
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue