Painless loop on geopoints array

Hi there!

I'm trying to loop over a geo_point array in my painless script, but I can't find a way to make it work.
My script is called in a script_score stage.

Here is the part of code not working :

for (def i=0; i < doc['locations'].values.length; i++) {
    distance = Math.min(distance, doc['locations'].values[i].arcDistance(lat, lon) * 0.001);
}

And here's what I get :

"type": "script_exception",
"reason": "runtime error",
"script_stack": [
      "distance = Math.min(distance, doc['locations'].values[i].arcDistance(lat, lon) * 0.001); }",
      "                                                        ^---- HERE"
],

I also have this :
"reason": "Unable to find dynamic method [arcDistance] with [2] arguments for class [org.elasticsearch.common.geo.GeoPoint]."
I tried multiple things with my i...

Do anyone of you see what I'm doing wrong?

Thank you!

I've found a few things from here https://github.com/elastic/elasticsearch/issues/25796

And as the only suggestion is labelled for v7.0, I used the last answer loop, which calculates the distance without the arcDistance function...

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