Closed
Description
Consider the following classes for whitelisting:
- org.elasticsearch.common.unit.DistanceUnit
- org.elasticsearch.common.geo.GeoUtils
- org.elasticsearch.common.geo.GeoDistance
For the purposes of performing unit conversions when doing arc distance calculations.
Alternatively provide functions in Painless that wrap necessary classes to perform the same unit conversions and calculations.
These examples (though these are groovy examples rather than painless ones, the use case is still valid). These examples require whitelisting of the classes involved.
Using DistanceUnit and GeoUtils classes:
GET /test/type/_search
{
"script_fields" : {
"test1" : {
"script" : {
"lang": "groovy",
"inline": "org.elasticsearch.common.unit.DistanceUnit.MILES.fromMeters(org.elasticsearch.common.geo.GeoUtils.arcDistance(0.0, 0.0, 1.0, 1.0))"
}
}
}
}
alternatively using GeoDistance and DistanceUnit classes:
_source['NETWORK_LOCATION'].collectEntries { it -> if (it != null && it.COORDINATES != null){ [(it.PCO_NET_LOC_CYCLE_CK.toString()) : org.elasticsearch.common.geo.GeoDistance.ARC.calculate(it.COORDINATES.lat, it.COORDINATES.lon, lat, lon, org.elasticsearch.common.unit.DistanceUnit.MILES)]} else{[('-1'):'-1']}}