# Return distance when using location-based scoring

**URL:** <https://discuss.elastic.co/t/return-distance-when-using-location-based-scoring/17848>\
**Category:** Elasticsearch\
**Created:** [June 1, 2014, 4:11pm UTC](https://discuss.elastic.co/t/return-distance-when-using-location-based-scoring/17848 "2014-06-01T16:11:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Louison\_Dumont](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/louison_dumont/32/1525_2.png) [@Louison\_Dumont](https://discuss.elastic.co/u/Louison_Dumont)\
**Post date:** [June 1, 2014, 4:11pm UTC](https://discuss.elastic.co/t/return-distance-when-using-location-based-scoring/17848/1 "2014-06-01T16:11:53Z")

</div>

I use _function\_score_ to create my custom score based on the distance  
between the user and a place.

"function\_score": {  
"functions": [  
{  
"gauss": {  
"location": {  
"origin": "47.3942675,0.6949399",  
"scale": "40km",  
"decay": 0.5  
}  
}  
}  
],  
"query": { ... // my query

It works quite well. But I wan't ElasticSearch to return the distance (in  
km) for each result. I added:

"sort" : [  
{  
"\_geo\_distance" : {  
"location" : [0.6949399,47.3942675],  
"order" : "asc",  
"unit" : "km"  
}  
}  
]

I was wondering... is it the proper way to do it ? Does it force ES to  
calculate the distance twice (for scoring & sorting) ? or is it just ok ?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9e5d1312-130a-4979-9651-4f5adaaadc6d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9e5d1312-130a-4979-9651-4f5adaaadc6d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:25am UTC](https://discuss.elastic.co/t/return-distance-when-using-location-based-scoring/17848/2 "2017-07-06T01:25:26Z")

</div>


