# how geo\_distance query works under the hood in Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-geo-distance-query-works-under-the-hood-in-elasticsearch/335154>\
**Category:** Elasticsearch\
**Created:** [June 4, 2023, 9:26am UTC](https://discuss.elastic.co/t/how-geo-distance-query-works-under-the-hood-in-elasticsearch/335154 "2023-06-04T09:26:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maulik\_trapasiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maulik_trapasiya/32/121816_2.png) [@maulik\_trapasiya](https://discuss.elastic.co/u/maulik_trapasiya)\
**Post date:** [June 4, 2023, 9:26am UTC](https://discuss.elastic.co/t/how-geo-distance-query-works-under-the-hood-in-elasticsearch/335154/1 "2023-06-04T09:26:20Z")

</div>

I need to use geo\_distance query on Elasticsearch. Need info about how it works under the hood and what is latency? I am not able to find any doc relevant to this. please help

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 4, 2023, 8:38pm UTC](https://discuss.elastic.co/t/how-geo-distance-query-works-under-the-hood-in-elasticsearch/335154/2 "2023-06-04T20:38:32Z")

</div>

Hi @maulik_trapasiya Welcome to the community....

First with respect to latency, we can not tell you that as there are many factors... the size of your data set, the filters, the number of results within the distance, the HW profile etc.. etc... I would encourage you to do your own testing.

And you can look at the benchmarks here

[https://elasticsearch-benchmarks.elastic.co/](https://elasticsearch-benchmarks.elastic.co/)

I am not the Geo Expert but here is the code and it shows the simple calculations... there are planar and arc calculations.

> <https://github.com/elastic/elasticsearch/blob/6179ae84f0cda5e2cb9e8070bcd88ce5ae699b9d/server/src/main/java/org/elasticsearch/common/geo/GeoUtils.java#L503>

and further here, I think the formulae are here

> <https://github.com/elastic/elasticsearch/blob/6179ae84f0cda5e2cb9e8070bcd88ce5ae699b9d/libs/geo/src/main/java/org/elasticsearch/geometry/simplify/SloppyMath.java#L31>

It looks like it follows the [Haversine](https://en.wikipedia.org/wiki/Haversine_formula) for the Arc distance method and the distance using a simple tangential plane for the planar distance, Whether this is precise enough for your use case is up to you perhaps you can provide further information if needed and we can take a deeper look.

---

<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 2, 2023, 8:38pm UTC](https://discuss.elastic.co/t/how-geo-distance-query-works-under-the-hood-in-elasticsearch/335154/3 "2023-07-02T20:38:44Z")

</div>

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