# arcDistance using \_source in painless script

**URL:** <https://discuss.elastic.co/t/arcdistance-using--source-in-painless-script/71287>\
**Category:** Elasticsearch\
**Created:** [January 11, 2017, 10:59pm UTC](https://discuss.elastic.co/t/arcdistance-using--source-in-painless-script/71287 "2017-01-11T22:59:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brian/32/54874_2.png) [@brian](https://discuss.elastic.co/u/brian)\
**Post date:** [January 11, 2017, 10:59pm UTC](https://discuss.elastic.co/t/arcdistance-using--source-in-painless-script/71287/1 "2017-01-11T22:59:06Z")

</div>

I was trying to use arcDistance using the following:

```
PUT /my_locations
{
    "mappings": {
        "location": {
            "properties": {
                "pin": {
                    "properties": {
                        "location": {
                            "type": "geo_point"
                        }
                    }
                }
            }
        }
    }
}

PUT /my_locations/location/1
{
    "pin" : {
        "location" : {
            "lat" : 40.12,
            "lon" : -71.34
        }
    }
}

GET /my_locations/location/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "200km",
                    "pin.location" : {
                        "lat" : 40,
                        "lon" : -70
                    }
                }
            }
        }
    },

    "script_fields": {
								"closest_listing" : {
									"script": {
										"lang": "painless",
										"inline": "return params._source.pin.location.arcDistance(40.0,-72.0)"
										}
									}
								}
}

```

when I execute the query I get

```
{
  "took": 32,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 4,
    "failed": 1,
    "failures": [
      {
        "shard": 3,
        "index": "my_locations",
        "node": "4Ts84JXZTiCaQjSx-7q7MQ",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Unable to find dynamic method [arcDistance] with [2] arguments for class [java.util.HashMap]."
          },
          "script_stack": [
            "return params._source.pin.location.arcDistance(40.0,-72.0)",
            " ^---- HERE"
          ],
          "script": "return params._source.pin.location.arcDistance(40.0,-72.0)",
          "lang": "painless"
        }
      }
    ]
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": []
  }
}

```

Is it possible to calculate the distance using \_source? I need to because I store multiple geo\_points in an array per document and want to calculate the closest distance.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 8, 2017, 10:59pm UTC](https://discuss.elastic.co/t/arcdistance-using--source-in-painless-script/71287/2 "2017-02-08T22:59:13Z")

</div>

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