# Efficiency of distance calculations

**URL:** <https://discuss.elastic.co/t/efficiency-of-distance-calculations/4428>\
**Category:** Elasticsearch\
**Created:** [May 17, 2011, 7:18pm UTC](https://discuss.elastic.co/t/efficiency-of-distance-calculations/4428 "2011-05-17T19:18:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Greg](https://discuss.elastic.co/u/Greg)\
**Post date:** [May 17, 2011, 7:18pm UTC](https://discuss.elastic.co/t/efficiency-of-distance-calculations/4428/1 "2011-05-17T19:18:02Z")

</div>

If I sort by "\_geo\_distance" and add a "geo\_distance" filter, both  
using the same location as the origin, does ES calculate the distances  
twice, or does it cache and re-use this information? If it is cached,  
how long for?

Many thanks  
Greg

---

<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:** [May 17, 2011, 7:21pm UTC](https://discuss.elastic.co/t/efficiency-of-distance-calculations/4428/2 "2011-05-17T19:21:54Z")

</div>

The distance calculation is not cached (debatable if caching will actually be slower..., need to test and see). The values for lat and lon are "cached".  
On Tuesday, May 17, 2011 at 10:18 PM, Greg wrote:

> If I sort by "\_geo\_distance" and add a "geo\_distance" filter, both  
> using the same location as the origin, does ES calculate the distances  
> twice, or does it cache and re-use this information? If it is cached,  
> how long for?
> 
> Many thanks  
> Greg

---

<div class="post-metadata">

**Author:** ![Greg](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Greg](https://discuss.elastic.co/u/Greg)\
**Post date:** [May 17, 2011, 7:30pm UTC](https://discuss.elastic.co/t/efficiency-of-distance-calculations/4428/3 "2011-05-17T19:30:07Z")

</div>

Thanks Shay!

On May 17, 8:21 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> The distance calculation is not cached (debatable if caching will actually be slower..., need to test and see). The values for lat and lon are "cached".
> 
> On Tuesday, May 17, 2011 at 10:18 PM, Greg wrote:
> 
> > If I sort by "\_geo\_distance" and add a "geo\_distance" filter, both  
> > using the same location as the origin, does ES calculate the distances  
> > twice, or does it cache and re-use this information? If it is cached,  
> > how long for?
> 
> > Many thanks  
> > Greg

---

<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:05am UTC](https://discuss.elastic.co/t/efficiency-of-distance-calculations/4428/4 "2017-07-06T04:05:55Z")

</div>

Closed on July 6, 2017, 4:05am UTC


