# Range query for geolocation in elasticsearch 6.x

**URL:** <https://discuss.elastic.co/t/range-query-for-geolocation-in-elasticsearch-6-x/136688>\
**Category:** Elasticsearch\
**Created:** [June 20, 2018, 12:30pm UTC](https://discuss.elastic.co/t/range-query-for-geolocation-in-elasticsearch-6-x/136688 "2018-06-20T12:30:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adesai](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@adesai](https://discuss.elastic.co/u/adesai)\
**Post date:** [June 20, 2018, 12:30pm UTC](https://discuss.elastic.co/t/range-query-for-geolocation-in-elasticsearch-6-x/136688/1 "2018-06-20T12:30:17Z")

</div>

Hello,

How do I migrate the following range query used for geo location in elasticsearch 2.x to elasticsearch 6.x as it does not return any results in 6.x?

BoolQueryBuilder result;  
result.must(QueryBuilders.rangeQuery("location.lat").gte(form.getMinLat()).lte(form.getMaxLat()));

result.must(QueryBuilders.rangeQuery("location.lon").gte(form.getMinLng()).lte(form.getMaxLng()));

I tried using the following in elasticsearch 6.x however it does not return the same results as in elasticsearch 2.x?

result.must(QueryBuilders.geoBoundingBoxQuery("location")  
.setCorners(form.getMaxLat(), form.getMaxLng(), form.getMinLat(), form.getMinLng()))

Any help is highly appreciated.

Thanks.

---

<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 18, 2018, 12:30pm UTC](https://discuss.elastic.co/t/range-query-for-geolocation-in-elasticsearch-6-x/136688/2 "2018-07-18T12:30:26Z")

</div>

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