The GeoDistance field expression returns the distance between a POINT value and a center point. This distance can be returned in meters, kilometers, yards, miles, and nautical miles. The returned distance will be in kilometers by default.
Example:
QueryRequest request = new QueryRequest("*:*"); request.addField("*"); // Get all stored fields // Calculate distance (in miles) from (lat,lon) of 73.5, 83.2 (in degrees) // Field name for distance will be "geo.distance" request.addField( new GeoDistance("position", 73.5, 83.2, GeoDistance.MILES, "geo.distance") ); // ... (Perform Search)
REST Syntax:
GEODISTANCE(FIELDEXPRESSION, LATITUDE, LONGITUDE, UNITS, DISTANCEUNITS)
- FIELDEXPRESSION - field expression to calculate distance from center point for
- LATITUDE - latitude for center point
- LONGITUDE - longitude for center point
- DISTANCEUNITS - distance units to represent returned value in (MILES, KILOMETERS, METERS, YARDS) (default = KILOMETERS)
Example:
&fields=GEODISTANCE(position, 73.5, 83.2, MILES) AS geo.distance