# Problem with geo\_distance filter

**URL:** <https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367>\
**Category:** Elasticsearch\
**Created:** [September 24, 2010, 8:03pm UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367 "2010-09-24T20:03:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_Bowman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_bowman/32/2546_2.png) [@Sean\_Bowman](https://discuss.elastic.co/u/Sean_Bowman)\
**Post date:** [September 24, 2010, 8:03pm UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/1 "2010-09-24T20:03:17Z")

</div>

I tried following the examples, but I can't seem to make a  
geo\_distance (or any geo filter) work, using 0.10.0. Here's my steps,  
after starting the search index:

$ curl -XPUT '[http://localhost:9200/test](http://localhost:9200/test)'

$ curl -XPUT '[http://localhost:9200/test/pins/1](http://localhost:9200/test/pins/1)' -d '{  
"pin" : {  
"location" : {  
"lat" : 40.12,  
"lon" : -71.34  
},  
"tag" : ["food", "family"],  
"text" : "my favorite family restaurant"  
}  
}'

$ curl -XGET '[http://localhost:9200/test/pins/\_search](http://localhost:9200/test/pins/_search)' -d '  
{ "query" : {  
"filtered" : {  
"query" : {  
"field" : { "text" : "restaurant" }  
},  
"filter" : {  
"geo\_distance" : {  
"distance" : "12km",  
"pin.location" : {  
"lat" : 40,  
"lon" : -70  
}  
}  
}  
}  
}  
}'

The result:

{"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":  
0,"max\_score":null,"hits":[]}}

Can anyone tell me what I'm doing wrong here?

Thanks.

---

<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:** [September 24, 2010, 8:15pm UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/2 "2010-09-24T20:15:21Z")

</div>

Hey,

The distance between the mentioned point is 114.94km, so you need to  
broaden your search. A few pointers:

1. After indexing data, you will see the changes after 1 second (give or  
take). If you test (i.e. execute fast consecutive curl requests, execute  
refresh before the search).
2. If you want to check some distances, you can do a match\_all query and  
sort by geo\_distance, this will give you the actual distances (sort values  
are returned as part of the search):  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/sort/#Geo\_Distance\_Sorting](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/sort/#Geo_Distance_Sorting)  
.

-shay.banon

On Fri, Sep 24, 2010 at 10:03 PM, Sean Bowman [pico303@gmail.com](mailto:pico303@gmail.com) wrote:

> I tried following the examples, but I can't seem to make a  
> geo\_distance (or any geo filter) work, using 0.10.0. Here's my steps,  
> after starting the search index:
> 
> $ curl -XPUT '[http://localhost:9200/test](http://localhost:9200/test)'
> 
> $ curl -XPUT '[http://localhost:9200/test/pins/1](http://localhost:9200/test/pins/1)' -d '{  
> "pin" : {  
> "location" : {  
> "lat" : 40.12,  
> "lon" : -71.34  
> },  
> "tag" : ["food", "family"],  
> "text" : "my favorite family restaurant"  
> }  
> }'
> 
> $ curl -XGET '[http://localhost:9200/test/pins/\_search](http://localhost:9200/test/pins/_search)' -d '  
> { "query" : {  
> "filtered" : {  
> "query" : {  
> "field" : { "text" : "restaurant" }  
> },  
> "filter" : {  
> "geo\_distance" : {  
> "distance" : "12km",  
> "pin.location" : {  
> "lat" : 40,  
> "lon" : -70  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> The result:
> 
> {"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":  
> 0,"max\_score":null,"hits":}}
> 
> Can anyone tell me what I'm doing wrong here?
> 
> Thanks.

---

<div class="post-metadata">

**Author:** ![Sean\_Bowman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_bowman/32/2546_2.png) [@Sean\_Bowman](https://discuss.elastic.co/u/Sean_Bowman)\
**Post date:** [September 24, 2010, 9:37pm UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/3 "2010-09-24T21:37:00Z")

</div>

Changing the range worked...finally! _fireworks_ Thank you. I should  
have checked that.

The sort idea is a good one too. Thanks for that reference. I can't  
tell you how refreshing it is to have someone on a mailing list point  
me at the correct documentation, rather than just tell me to read  
everything on the entire site or type keywords into Google. 🙂

Just so you know, this is the example from your blog article and the  
geo\_distance filter doc on the web site. You might want to update the  
documentation you've got up there and increase that "12km" to  
"200km". There's also a typo in the sample JSON: no comma after the  
"distance" : "12km" line. And while not technically a error, on the  
sort documentation page, your query centers on [-40, 70], while your  
examples were always [40, -70]. For consistency, you might want to  
swap the negative there. Took me a second of wondering how I got  
16000+km when you found 114km, before I realized the signs were  
reversed.

This is only day two of using ElasticSearch, and I'm loving the  
product. Outstanding work.

---

<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:** [September 24, 2010, 9:58pm UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/4 "2010-09-24T21:58:35Z")

</div>

Hi,

Thanks for the doc notes, pushed a fix for that.

-shay.banon

On Fri, Sep 24, 2010 at 11:37 PM, Sean Bowman [pico303@gmail.com](mailto:pico303@gmail.com) wrote:

> Changing the range worked...finally! _fireworks_ Thank you. I should  
> have checked that.
> 
> The sort idea is a good one too. Thanks for that reference. I can't  
> tell you how refreshing it is to have someone on a mailing list point  
> me at the correct documentation, rather than just tell me to read  
> everything on the entire site or type keywords into Google. 🙂
> 
> Just so you know, this is the example from your blog article and the  
> geo\_distance filter doc on the web site. You might want to update the  
> documentation you've got up there and increase that "12km" to  
> "200km". There's also a typo in the sample JSON: no comma after the  
> "distance" : "12km" line. And while not technically a error, on the  
> sort documentation page, your query centers on [-40, 70], while your  
> examples were always [40, -70]. For consistency, you might want to  
> swap the negative there. Took me a second of wondering how I got  
> 16000+km when you found 114km, before I realized the signs were  
> reversed.
> 
> This is only day two of using Elasticsearch, and I'm loving the  
> product. Outstanding work.

---

<div class="post-metadata">

**Author:** ![dcosta72](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcosta72/32/3252_2.png) [@dcosta72](https://discuss.elastic.co/u/dcosta72)\
**Post date:** [March 23, 2011, 11:16pm UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/5 "2011-03-23T23:16:34Z")

</div>

I have been following the examples (0.15.2 and even tried 0.10.0) too and I can not get the geo\_distance filter to work either.

Any help will be greatly appreciated.

This is what I am posting:

$ curl -XPUT '[http://localhost:9200/test6/pins/1](http://localhost:9200/test6/pins/1)' -d '{  
"pin" : {  
"location" : {  
"lat" : 40.12,  
"lon" : -71.34  
},  
"tag" : ["food", "family"],  
"text" : "my favorite family restaurant"  
}  
}'

$ curl -XPUT '[http://localhost:9200/test6/\_mapping](http://localhost:9200/test6/_mapping)' -d '  
{  
"pin" : {  
"properties" : {  
"location" : {  
"type" : "geo\_point"  
}  
}  
}  
}'

$ curl -XGET '[http://localhost:9200/test6/pins/\_search](http://localhost:9200/test6/pins/_search)' -d '  
{ "query" : {  
"filtered" : {  
"query" : {  
"match\_all" : {}  
},  
"filter" : {  
"geo\_distance" : {  
"distance" : "1025km",  
"pin.location" : {  
"lat" : 40,  
"lon" : -70  
}  
}  
}  
}  
}  
}'

---

<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:** [March 25, 2011, 7:02pm UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/6 "2011-03-25T19:02:16Z")

</div>

Make sure to put the mappings before you index the document.  
On Thursday, March 24, 2011 at 1:16 AM, dcosta72 wrote:

> I have been following the examples (0.15.2 and even tried 0.10.0) too and I  
> can not get the geo\_distance filter to work either.
> 
> Any help will be greatly appreciated.
> 
> This is what I am posting:
> 
> $ curl -XPUT '[http://localhost:9200/test6/pins/1](http://localhost:9200/test6/pins/1)' -d '{  
> "pin" : {  
> "location" : {  
> "lat" : 40.12,  
> "lon" : -71.34  
> },  
> "tag" : ["food", "family"],  
> "text" : "my favorite family restaurant"  
> }  
> }'
> 
> $ curl -XPUT '[http://localhost:9200/test6/\_mapping](http://localhost:9200/test6/_mapping)' -d '  
> {  
> "pin" : {  
> "properties" : {  
> "location" : {  
> "type" : "geo\_point"  
> }  
> }  
> }  
> }'
> 
> $ curl -XGET '[http://localhost:9200/test6/pins/\_search](http://localhost:9200/test6/pins/_search)' -d '  
> { "query" : {  
> "filtered" : {  
> "query" : {  
> "match\_all" : {}  
> },  
> "filter" : {  
> "geo\_distance" : {  
> "distance" : "1025km",  
> "pin.location" : {  
> "lat" : 40,  
> "lon" : -70  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Problem-with-geo-distance-filter-tp1576354p2722899.html](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-geo-distance-filter-tp1576354p2722899.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![dcosta72](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcosta72/32/3252_2.png) [@dcosta72](https://discuss.elastic.co/u/dcosta72)\
**Post date:** [March 27, 2011, 11:34pm UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/7 "2011-03-27T23:34:57Z")

</div>

Thanks Shay,

Unfortunately I can not get it working. I have tried many different approaches and it just doesn't work for me... I would really appreciate a full working example on 0.15.2, with mapping included.

I am new to ES and I would like to use it for a project I am working on, but I need the geo\_distance search to work...

Apologies if I am missing something obvious. I have spent already a few days with this...

Thanks again.

---

<div class="post-metadata">

**Author:** ![dcosta72](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcosta72/32/3252_2.png) [@dcosta72](https://discuss.elastic.co/u/dcosta72)\
**Post date:** [March 28, 2011, 10:06am UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/8 "2011-03-28T10:06:08Z")

</div>

I got it working. I got slightly confused with the entities involved.

Thanks again for your response.

ES is an outstanding product. Excellent work.

---

<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:** [March 30, 2011, 10:51am UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/9 "2011-03-30T10:51:27Z")

</div>

gist what you are doing, we can take it from there.  
On Monday, March 28, 2011 at 1:34 AM, dcosta72 wrote:

> Thanks Shay,
> 
> Unfortunately I can not get it working. I have tried many different  
> approaches and it just doesn't work for me... I would really appreciate a  
> full working example on 0.15.2, with mapping included.
> 
> I am new to ES and I would like to use it for a project I am working on, but  
> I need the geo\_distance search to work...
> 
> Apologies if I am missing something obvious. I have spent already a few days  
> with this...
> 
> Thanks again.
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Problem-with-geo-distance-filter-tp1576354p2741050.html](http://elasticsearch-users.115913.n3.nabble.com/Problem-with-geo-distance-filter-tp1576354p2741050.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:09am UTC](https://discuss.elastic.co/t/problem-with-geo-distance-filter/3367/10 "2017-07-06T04:09:08Z")

</div>


