How to iterate over Geopoints in painless?

Hi,

I have a painless script, it iterate over a set of geopoints and compute the shortest distance.
But it seems that there is an error:

"script_fields": {
"distance": {
"script": {
"source": "double d = Double.MAX_VALUE; for (gp in doc['geoLocations']) d = Math.min(d, gp.planeDistance(params.lat,params.lon) * 0.001); return d;",
"lang": "painless",
"params": {
"lat": {{latitude}},
"lon": {{longitude}}
}
}
}

Here is the error message:
"reason": "dynamic method [org.elasticsearch.common.geo.GeoPoint, planeDistance/2] not found"

I have checked my mapping and I have this:

    "geoLocations": {
      "type": "geo_point"
    }

So, if someone has an idea of the issue ?

Thanks

I quickly peeked into the source, and you should have a method like doc['geoLocations'].planeDistance(lat, lon)...

hope this helps!

Thanks, but the problem with this solution is that it only use the first geopoints, I'm looking for the closest one.

Indeed. feel free to open a feature report in github.

Just to make sure I understand the problem space fully: Can you send an additional search request and sort by geo distance instead of using a script? Do you have to use scripting here?

See https://www.elastic.co/guide/en/elasticsearch/reference/7.8/sort-search-results.html#geo-sorting

Thanks for your suggestion,

Such request exist since a long time, see:

In the current situation, the script is necessary... it allows me to generate fields for debugging my DSL ! I will remove it in production.

It is to debug another query, that use distance_feature (That I can't make it work):

My sorting is based on multiples criterions... not only the distance.

But anyway, I suspect that I should use it in my query... (I don't like this, but maybe there are no other choices).

BTW, I can request the feature on GitHub, but the problem is that I need something asap to enter in production, you see :wink:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.