# Geo Distance calculation using script fields in v5.0.1 \[reason\] Unable to find dynamic method \[distanceInKm\]

**URL:** <https://discuss.elastic.co/t/geo-distance-calculation-using-script-fields-in-v5-0-1-reason-unable-to-find-dynamic-method-distanceinkm/69028>\
**Category:** Elasticsearch\
**Created:** [December 14, 2016, 2:19pm UTC](https://discuss.elastic.co/t/geo-distance-calculation-using-script-fields-in-v5-0-1-reason-unable-to-find-dynamic-method-distanceinkm/69028 "2016-12-14T14:19:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![patlola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patlola/32/14190_2.png) [@patlola](https://discuss.elastic.co/u/patlola)\
**Post date:** [December 14, 2016, 2:19pm UTC](https://discuss.elastic.co/t/geo-distance-calculation-using-script-fields-in-v5-0-1-reason-unable-to-find-dynamic-method-distanceinkm/69028/1 "2016-12-14T14:19:28Z")

</div>

```
{
  "script_fields": {
    "distance": {
      "script": {
        "inline": "doc['location'].distanceInKm(12.898365,77.594359)"
      }
    }
  }
}

```

mappings  
"location": {  
"type": "geo\_point"  
}  
got the following error as unable to find dynamic method distanceInKm

```
"reason": {
	"type": "script_exception",
	"reason": "runtime error",
	"caused_by": {
		"type": "illegal_argument_exception",
		"reason": "Unable to find dynamic method [distanceInKm] with [2] arguments for class [org.elasticsearch.index.fielddata.ScriptDocValues.GeoPoints]."
	},
	"script_stack": ["doc['location'].distanceInKm(12.898365,77.594359)", " ^---- HERE"],
	"script": "doc['location'].distanceInKm(12.898365,77.594359)",
	"lang": "painless"
}

```

tried reading all the docs unable to resolve this. hope the folks here will help me solve this.  
I was abe to find distance using sort functionality but distanceInKM is not working!  
is it a bug or my query is wrong ?

---

<div class="post-metadata">

**Author:** ![patlola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patlola/32/14190_2.png) [@patlola](https://discuss.elastic.co/u/patlola)\
**Post date:** [December 15, 2016, 7:48am UTC](https://discuss.elastic.co/t/geo-distance-calculation-using-script-fields-in-v5-0-1-reason-unable-to-find-dynamic-method-distanceinkm/69028/2 "2016-12-15T07:48:51Z")

</div>

@dadoonet can you please help on this ?

---

<div class="post-metadata">

**Author:** ![patlola](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patlola/32/14190_2.png) [@patlola](https://discuss.elastic.co/u/patlola)\
**Post date:** [December 28, 2016, 2:59pm UTC](https://discuss.elastic.co/t/geo-distance-calculation-using-script-fields-in-v5-0-1-reason-unable-to-find-dynamic-method-distanceinkm/69028/3 "2016-12-28T14:59:01Z")

</div>

distanceInKm is deprecated in V5.0 version using [https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking\_50\_scripting.html#\_geopoint\_scripts](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_50_scripting.html#_geopoint_scripts)

---

<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:** [January 25, 2017, 2:59pm UTC](https://discuss.elastic.co/t/geo-distance-calculation-using-script-fields-in-v5-0-1-reason-unable-to-find-dynamic-method-distanceinkm/69028/4 "2017-01-25T14:59:11Z")

</div>

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