diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java index 3ee18a9515e..17fd52ad41e 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java @@ -1271,6 +1271,46 @@ public class SimpleIndexQueryParserTests { assertThat(filter.lon(), closeTo(-70, 0.00001)); assertThat(filter.distance(), closeTo(12, 0.00001)); } + + @Test public void testGeoDistanceFilter9() throws IOException { + IndexQueryParser queryParser = queryParser(); + String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance9.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 testGeoDistanceFilter10() throws IOException { + IndexQueryParser queryParser = queryParser(); + String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance10.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 testGeoDistanceFilter11() throws IOException { + IndexQueryParser queryParser = queryParser(); + String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance11.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"); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance10.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance10.json new file mode 100644 index 00000000000..6d08ae7e638 --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance10.json @@ -0,0 +1,17 @@ +{ + "filtered" : { + "query" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : 19.312128, + "unit": "km", + "person.location" : { + "lat" : 40, + "lon" : -70 + } + } + } + } +} diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance11.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance11.json new file mode 100644 index 00000000000..77ebf781bc2 --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance11.json @@ -0,0 +1,16 @@ +{ + "filtered" : { + "query" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "19.312128km", + "person.location" : { + "lat" : 40, + "lon" : -70 + } + } + } + } +} diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance9.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance9.json new file mode 100644 index 00000000000..2e62052516a --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance9.json @@ -0,0 +1,17 @@ +{ + "filtered" : { + "query" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "19.312128", + "unit": "km", + "person.location" : { + "lat" : 40, + "lon" : -70 + } + } + } + } +}