# Geospatial proximity search within a certain radius sorted by distance

**URL:** <https://discuss.elastic.co/t/geospatial-proximity-search-within-a-certain-radius-sorted-by-distance/8393>\
**Category:** Elasticsearch\
**Created:** [July 12, 2012, 2:09am UTC](https://discuss.elastic.co/t/geospatial-proximity-search-within-a-certain-radius-sorted-by-distance/8393 "2012-07-12T02:09:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Paul\_Hus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrick_paul_hus/32/2816_2.png) [@Patrick\_Paul\_Hus](https://discuss.elastic.co/u/Patrick_Paul_Hus)\
**Post date:** [July 12, 2012, 2:09am UTC](https://discuss.elastic.co/t/geospatial-proximity-search-within-a-certain-radius-sorted-by-distance/8393/1 "2012-07-12T02:09:33Z")

</div>

Hi,

I started playing around today with Elasticsearch. I indexed a couple of  
documents that look like this :

{  
"location": {  
"name": "Montreal",  
"location": {"lat": 45.50884, "lon": -73.58781}  
}  
}

and then I know that I can do something like this to get the locations that  
are nearest first

{  
"query" : {  
"match\_all" : {}  
},  
"sort" : [{  
"\_geo\_distance": {  
"location": {  
"lat": 45.5247,  
"lon": -73.5894  
},  
"order": "asc",  
"unit": "km"  
}  
}]  
}'

but how can I also specify that I also only want the locations that are  
within a given distance/radius?

---

<div class="post-metadata">

**Author:** ![Mario\_Menezes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mario_menezes/32/2812_2.png) [@Mario\_Menezes](https://discuss.elastic.co/u/Mario_Menezes)\
**Post date:** [July 12, 2012, 2:00pm UTC](https://discuss.elastic.co/t/geospatial-proximity-search-within-a-certain-radius-sorted-by-distance/8393/2 "2012-07-12T14:00:37Z")

</div>

Hi,

I'm not an expert - far from this. But I found this on the docs. Maybe  
it's what you want, isn't it?

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Regards,

Em quarta-feira, 11 de julho de 2012 23h09min33s UTC-3, Patrick Paul-Hus  
escreveu:

> Hi,
> 
> I started playing around today with Elasticsearch. I indexed a couple of  
> documents that look like this :
> 
> {  
> "location": {  
> "name": "Montreal",  
> "location": {"lat": 45.50884, "lon": -73.58781}  
> }  
> }
> 
> and then I know that I can do something like this to get the locations  
> that are nearest first
> 
> {  
> "query" : {  
> "match\_all" : {}  
> },  
> "sort" : [{  
> "\_geo\_distance": {  
> "location": {  
> "lat": 45.5247,  
> "lon": -73.5894  
> },  
> "order": "asc",  
> "unit": "km"  
> }  
> }]  
> }'
> 
> but how can I also specify that I also only want the locations that are  
> within a given distance/radius?

---

<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, 3:20am UTC](https://discuss.elastic.co/t/geospatial-proximity-search-within-a-certain-radius-sorted-by-distance/8393/3 "2017-07-06T03:20:30Z")

</div>


