# Using geo distance in custom\_score

**URL:** https://discuss.elastic.co/t/using-geo-distance-in-custom-score/3750
**Category:** Elasticsearch
**Created:** [January 6, 2011, 6:01am UTC](https://discuss.elastic.co/t/using-geo-distance-in-custom-score/3750 "2011-01-06T06:01:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mattias\_Pfeiffer](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@Mattias\_Pfeiffer](https://discuss.elastic.co/u/Mattias_Pfeiffer)
#### Post date: [January 6, 2011, 6:01am UTC](https://discuss.elastic.co/t/using-geo-distance-in-custom-score/3750/1 "2011-01-06T06:01:03Z")

</div>

Hi,

Thanks for a great product!

Is there a way to use a geo distance in a custom\_score? Should I wrap  
my custom\_score around a \_geo\_distance-sort filter? I do not want to  
filter by a distance, just calculate a custom score based on the  
distance from a fixed point.

Thanks!

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [January 6, 2011, 7:58am UTC](https://discuss.elastic.co/t/using-geo-distance-in-custom-score/3750/2 "2011-01-06T07:58:21Z")

</div>

Its not simple to access it from a script, but it should be. Something like  
(assuming params include lat and lon to compute the distance from):

doc['geo\_point\_field'].distance(lat, lon)

Can you open a feature for it? should be simple to implement.

On Thu, Jan 6, 2011 at 8:01 AM, Mattias Pfeiffer \<[mattias.pfeiffer@gmail.com](mailto:mattias.pfeiffer@gmail.com)

> wrote:

> Hi,
> 
> Thanks for a great product!
> 
> Is there a way to use a geo distance in a custom\_score? Should I wrap  
> my custom\_score around a \_geo\_distance-sort filter? I do not want to  
> filter by a distance, just calculate a custom score based on the  
> distance from a fixed point.
> 
> Thanks!

---

<div class="post-metadata">

### Author: ![Mattias\_Pfeiffer](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@Mattias\_Pfeiffer](https://discuss.elastic.co/u/Mattias_Pfeiffer)
#### Post date: [January 6, 2011, 2:21pm UTC](https://discuss.elastic.co/t/using-geo-distance-in-custom-score/3750/3 "2011-01-06T14:21:16Z")

</div>

Great - I've filed a feature request:

> <https://github.com/elastic/elasticsearch/issues/607>
>
> Feature request for distance calculator method in custom\_score queries, eg.:
> 
> \`\`…\`
> doc\['geo\_point\_field'\].distance(lat, lon)
> \`\`\`
> 
> The following methods are allowed:
> \- \`doc\['geo\_point\_field'\].distance(lat, lon)\`: Returns the distance in miles form lat/lon.
> \- \`doc\['geo\_point\_field'\].distanceInKm(lat, lon)\`: Returns the distance in km lat/lon.
> \- \`doc\['geo\_point\_field'\].geohashDistance(geohash)\`: Returns the distance in miles from geohash.
> \- \`doc\['geo\_point\_field'\].geohashDistanceInKm(geohash)\`: Returns the distance in km from geohash.

On Jan 6, 2:58 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Its not simple to access it from a script, but it should be. Something like  
> (assuming params include lat and lon to compute the distance from):
> 
> doc['geo\_point\_field'].distance(lat, lon)
> 
> Can you open a feature for it? should be simple to implement.
> 
> On Thu, Jan 6, 2011 at 8:01 AM, Mattias Pfeiffer \<[mattias.pfeif...@gmail.com](mailto:mattias.pfeif...@gmail.com)
> 
> > wrote:  
> > Hi,
> 
> > Thanks for a great product!
> 
> > Is there a way to use a geo distance in a custom\_score? Should I wrap  
> > my custom\_score around a \_geo\_distance-sort filter? I do not want to  
> > filter by a distance, just calculate a custom score based on the  
> > distance from a fixed point.
> 
> > Thanks!

---

<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: [July 6, 2017, 4:14am UTC](https://discuss.elastic.co/t/using-geo-distance-in-custom-score/3750/4 "2017-07-06T04:14:11Z")

</div>


