mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
NullPointerException in geo_distance_range without to, closes #1865.
This commit is contained in:
parent
20e968bf62
commit
03c9eaf812
@ -44,8 +44,6 @@ import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFi
|
||||
* "name.lon" : 1.2,
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||
|
||||
@ -123,8 +121,7 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||
}
|
||||
} else if (currentFieldName.equals("to")) {
|
||||
if (token == XContentParser.Token.VALUE_NULL) {
|
||||
}
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
} else if (token == XContentParser.Token.VALUE_STRING) {
|
||||
vTo = parser.text(); // a String
|
||||
} else {
|
||||
vTo = parser.numberValue(); // a Number
|
||||
@ -151,8 +148,7 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||
includeLower = true;
|
||||
} else if ("lt".equals(currentFieldName)) {
|
||||
if (token == XContentParser.Token.VALUE_NULL) {
|
||||
}
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
} else if (token == XContentParser.Token.VALUE_STRING) {
|
||||
vTo = parser.text(); // a String
|
||||
} else {
|
||||
vTo = parser.numberValue(); // a Number
|
||||
@ -160,8 +156,7 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||
includeUpper = false;
|
||||
} else if ("lte".equals(currentFieldName) || "le".equals(currentFieldName)) {
|
||||
if (token == XContentParser.Token.VALUE_NULL) {
|
||||
}
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
} else if (token == XContentParser.Token.VALUE_STRING) {
|
||||
vTo = parser.text(); // a String
|
||||
} else {
|
||||
vTo = parser.numberValue(); // a Number
|
||||
@ -210,20 +205,24 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
||||
}
|
||||
}
|
||||
|
||||
double from;
|
||||
double to;
|
||||
if (vFrom instanceof Number) {
|
||||
from = unit.toMiles(((Number) vFrom).doubleValue());
|
||||
} else {
|
||||
from = DistanceUnit.parse((String) vFrom, unit, DistanceUnit.MILES);
|
||||
Double from = null;
|
||||
Double to = null;
|
||||
if (vFrom != null) {
|
||||
if (vFrom instanceof Number) {
|
||||
from = unit.toMiles(((Number) vFrom).doubleValue());
|
||||
} else {
|
||||
from = DistanceUnit.parse((String) vFrom, unit, DistanceUnit.MILES);
|
||||
}
|
||||
from = geoDistance.normalize(from, DistanceUnit.MILES);
|
||||
}
|
||||
from = geoDistance.normalize(from, DistanceUnit.MILES);
|
||||
if (vTo instanceof Number) {
|
||||
to = unit.toMiles(((Number) vTo).doubleValue());
|
||||
} else {
|
||||
to = DistanceUnit.parse((String) vTo, unit, DistanceUnit.MILES);
|
||||
if (vTo != null) {
|
||||
if (vTo instanceof Number) {
|
||||
to = unit.toMiles(((Number) vTo).doubleValue());
|
||||
} else {
|
||||
to = DistanceUnit.parse((String) vTo, unit, DistanceUnit.MILES);
|
||||
}
|
||||
to = geoDistance.normalize(to, DistanceUnit.MILES);
|
||||
}
|
||||
to = geoDistance.normalize(to, DistanceUnit.MILES);
|
||||
|
||||
if (normalizeLat) {
|
||||
lat = GeoUtils.normalizeLat(lat);
|
||||
|
@ -80,6 +80,9 @@ public class GeoDistanceRangeFilter extends Filter {
|
||||
inclusiveUpperPoint = NumericUtils.sortableLongToDouble(includeUpper ? i : (i - 1L));
|
||||
} else {
|
||||
inclusiveUpperPoint = Double.POSITIVE_INFINITY;
|
||||
// we disable bounding box in this case, since the upper point is all and we create bounding box up to the
|
||||
// upper point it will effectively include all
|
||||
// TODO we can create a bounding box up to from and "not" it
|
||||
optimizeBbox = null;
|
||||
}
|
||||
|
||||
@ -153,7 +156,7 @@ public class GeoDistanceRangeFilter extends Filter {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GeoDistanceRangeFilter(" + fieldName + ", " + geoDistance + ", [" + inclusiveLowerPoint + " - " + inclusiveUpperPoint + "], " + lat + ", " + lon + ")";
|
||||
return "GeoDistanceRangeFilter(" + fieldName + ", " + geoDistance + ", [" + inclusiveLowerPoint + " - " + inclusiveUpperPoint + "], " + lat + ", " + lon + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -199,6 +199,18 @@ public class GeoDistanceTests extends AbstractNodesTests {
|
||||
assertThat(hit.id(), anyOf(equalTo("4"), equalTo("5")));
|
||||
}
|
||||
|
||||
searchResponse = client.prepareSearch() // from NY
|
||||
.setQuery(filteredQuery(matchAllQuery(), geoDistanceRangeFilter("location").to("2.0km").point(40.7143528, -74.0059731)))
|
||||
.execute().actionGet();
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(4l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(4));
|
||||
|
||||
searchResponse = client.prepareSearch() // from NY
|
||||
.setQuery(filteredQuery(matchAllQuery(), geoDistanceRangeFilter("location").from("2.0km").point(40.7143528, -74.0059731)))
|
||||
.execute().actionGet();
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
// SORTING
|
||||
|
||||
searchResponse = client.prepareSearch().setQuery(matchAllQuery())
|
||||
|
Loading…
x
Reference in New Issue
Block a user