The issue here is that calling .values
gives a list of GeoPoint()
objects. There is a work around, although we need to do a bit of extra work to pull in the appropriate Java classes. We need to have the latitude and longitude of both points.
import org.elasticsearch.common.geo.GeoDistance;
import org.elasticsearch.common.unit.DistanceUnit;
base_point = doc['base_location'].value;
if (!doc['location'].empty && doc['location'].values.length > 1) {
foreach (loc_index: doc['location'].values) {
distance = GeoDistance.PLANE.calculate(loc_index.lat, loc_index.lon, base_point.lat, base_point.lon, DistanceUnit.MILES);
}
}
We can get the result in different units described by the enumerable here. We can also use different calculation methodologies (like ARC), described here.