# Geo location distance sorting by proximity boost

**URL:** <https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [April 20, 2021, 6:14pm UTC](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749 "2021-04-20T18:14:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bskade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bskade/32/80493_2.png) [@bskade](https://discuss.elastic.co/u/bskade)\
**Post date:** [April 20, 2021, 6:14pm UTC](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749/1 "2021-04-20T18:14:11Z")

</div>

Hi,

we tried some kind of distance sorting by boosting the distance score impact.

pseudo code

options["boosts"] = {  
location: {  
type: "proximity",  
function: "exponential",  
center: options.facets.location.center,  
factor: 10  
}  
};

It seems to work for distances lower than ~25km, but on higher distances the score is always 1.  
Therefore boosting will have no affect. We tried all possible functions ( linear, proximity, exponential) and in addition higher factors.  
Any idea, how to increase the score for distances higher than 30km?

---

<div class="post-metadata">

**Author:** ![Irina\_Truong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irina_truong/32/112040_2.png) [@Irina\_Truong](https://discuss.elastic.co/u/Irina_Truong)\
**Post date:** [April 23, 2021, 11:00pm UTC](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749/2 "2021-04-23T23:00:20Z")

</div>

Hi,

Are you applying the "proximity" boost to a numeric field (distance), or to geolocation? It is, unfortunately, a known issue that proximity boost does not work so great on numbers right now, because it uses a static scale for the decay function, which is good for some but not all cases.

More details are available in [https://github.com/elastic/support-known-issues/issues/510](https://github.com/elastic/support-known-issues/issues/510).

---

<div class="post-metadata">

**Author:** ![bskade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bskade/32/80493_2.png) [@bskade](https://discuss.elastic.co/u/bskade)\
**Post date:** [April 26, 2021, 10:59am UTC](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749/3 "2021-04-26T10:59:23Z")

</div>

I would say geolocation  
based on this code  
options["boosts"] = {  
location: {  
type: "proximity",  
function: "exponential",  
center: options.facets.location.center,  
factor: 10  
}  
};

where options.facets.location.center is a geopoint

---

<div class="post-metadata">

**Author:** ![Irina\_Truong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irina_truong/32/112040_2.png) [@Irina\_Truong](https://discuss.elastic.co/u/Irina_Truong)\
**Post date:** [April 27, 2021, 8:45pm UTC](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749/4 "2021-04-27T20:45:12Z")

</div>

Hi,

My initial answer (based on the known issue above) was not full. The problem affects both geolocation and numeric fields, because for both of those, AppSearch will not allow you to provide a custom `scale` value. The default scale, in case of `geolocation` field type, is set to `1km`, and currently there's no way to change it.

We are aware that the user experience with this feature is not great right now, and there probably will be improvements in the future. For right now, unfortunately, there's no good solution.

---

<div class="post-metadata">

**Author:** ![Florian\_Stieger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/florian_stieger/32/78442_2.png) [@Florian\_Stieger](https://discuss.elastic.co/u/Florian_Stieger)\
**Post date:** [May 3, 2021, 9:27am UTC](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749/5 "2021-05-03T09:27:27Z")

</div>

I found a workaround for this bug. You can divide all your coordinates by a factor. I did factor 1000 for locations all within switzerland (you might even need a bigger factor). Now I get good results for all those locations.  
Obviously you also have to divide the center-coordinates.

---

<div class="post-metadata">

**Author:** ![Irina\_Truong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irina_truong/32/112040_2.png) [@Irina\_Truong](https://discuss.elastic.co/u/Irina_Truong)\
**Post date:** [May 3, 2021, 4:18pm UTC](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749/6 "2021-05-03T16:18:58Z")

</div>

@Florian_Stieger That's clever! Thank you for sharing the workaround.

---

<div class="post-metadata">

**Author:** ![Florian\_Stieger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/florian_stieger/32/78442_2.png) [@Florian\_Stieger](https://discuss.elastic.co/u/Florian_Stieger)\
**Post date:** [May 4, 2021, 7:03pm UTC](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749/7 "2021-05-04T19:03:21Z")

</div>

Is there any way to set the score to 0 or 1 (something const) before calculating the boost? Otherwise i'll allways end up with some kind of mess, because the values get mixed up slightly.

---

<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:** [June 1, 2021, 7:03pm UTC](https://discuss.elastic.co/t/geo-location-distance-sorting-by-proximity-boost/270749/8 "2021-06-01T19:03:24Z")

</div>

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