diff --git a/docs/reference/modules/scripting.asciidoc b/docs/reference/modules/scripting.asciidoc index b79e9e9ad44..cb707c7f57c 100644 --- a/docs/reference/modules/scripting.asciidoc +++ b/docs/reference/modules/scripting.asciidoc @@ -192,7 +192,14 @@ km) of this geo point field from the provided lat/lon with a default value. |`doc['field_name'].factorDistance(lat, lon, default)` |The distance factor of this geo point field from the provided lat/lon with a default value. +|`doc['field_name'].geohashDistance(geohash)` |The `arc` distance (in meters) +of this geo point field from the provided geohash. +|`doc['field_name'].geohashDistanceInKm(geohash)` |The `arc` distance (in km) +of this geo point field from the provided geohash. + +|`doc['field_name'].geohashDistanceInMiles(geohash)` |The `arc` distance (in +miles) of this geo point field from the provided geohash. |======================================================================= [float] diff --git a/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java b/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java index 2e56d580b10..e06977ffd5a 100644 --- a/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java +++ b/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java @@ -411,5 +411,24 @@ public abstract class ScriptDocValues { GeoPoint point = getValue(); return GeoDistance.PLANE.calculate(point.lat(), point.lon(), lat, lon, DistanceUnit.MILES); } + + public double geohashDistance(String geohash) { + GeoPoint point = getValue(); + GeoPoint p = new GeoPoint().resetFromGeoHash(geohash); + return GeoDistance.ARC.calculate(point.lat(), point.lon(), p.lat(), p.lon(), DistanceUnit.DEFAULT); + } + + public double geohashDistanceInKm(String geohash) { + GeoPoint point = getValue(); + GeoPoint p = new GeoPoint().resetFromGeoHash(geohash); + return GeoDistance.ARC.calculate(point.lat(), point.lon(), p.lat(), p.lon(), DistanceUnit.KILOMETERS); + } + + public double geohashDistanceInMiles(String geohash) { + GeoPoint point = getValue(); + GeoPoint p = new GeoPoint().resetFromGeoHash(geohash); + return GeoDistance.ARC.calculate(point.lat(), point.lon(), p.lat(), p.lon(), DistanceUnit.MILES); + } + } }