# Why is ascending geo distance sorting faster than descending geo distance sorting

**URL:** <https://discuss.elastic.co/t/why-is-ascending-geo-distance-sorting-faster-than-descending-geo-distance-sorting/173328>\
**Category:** Elasticsearch\
**Created:** [March 21, 2019, 2:17pm UTC](https://discuss.elastic.co/t/why-is-ascending-geo-distance-sorting-faster-than-descending-geo-distance-sorting/173328 "2019-03-21T14:17:57Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [March 22, 2019, 6:30am UTC](https://discuss.elastic.co/t/why-is-ascending-geo-distance-sorting-faster-than-descending-geo-distance-sorting/173328/4 "2019-03-22T06:30:05Z")

</div>

`LatLonDocValuesField.newDistanceSort` is a primitive implemented at Lucene level:

> <https://github.com/iverase/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/document/LatLonPointSortField.java>

The key of the algorithm is on `LatLonPointDistanceComparator`, the javadocs explain the strategy used. A bounding box from the min competitive distance is built and therefore we can reject points based on this bounding box instead of calculating the distance for every element which is expensive.

> <https://github.com/iverase/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceComparator.java>

---

_[View the full topic](https://discuss.elastic.co/t/why-is-ascending-geo-distance-sorting-faster-than-descending-geo-distance-sorting/173328)._
