# Geo search within country or continent

**URL:** <https://discuss.elastic.co/t/geo-search-within-country-or-continent/13481>\
**Category:** Elasticsearch\
**Created:** [September 5, 2013, 7:08pm UTC](https://discuss.elastic.co/t/geo-search-within-country-or-continent/13481 "2013-09-05T19:08:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfriedma](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mfriedma](https://discuss.elastic.co/u/mfriedma)\
**Post date:** [September 5, 2013, 7:08pm UTC](https://discuss.elastic.co/t/geo-search-within-country-or-continent/13481/1 "2013-09-05T19:08:51Z")

</div>

I'm new to elasticsearch. Thank you for this great product.

Our client would like to search within a region (continent), or within a  
country, or even near a city.

I have been reading about geo shapes etc. I'm trying to find out if there  
are any predefined shapes.

Are there predefined shapes for countries and continents within which we  
would search?

What strategies would one use to find all of the 'X' within North America  
for instance? (where X is something like 'Widget shops' and we have all the  
pins indexed for those shops)

Many thanks.

Matt

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [September 6, 2013, 6:12pm UTC](https://discuss.elastic.co/t/geo-search-within-country-or-continent/13481/2 "2013-09-06T18:12:59Z")

</div>

Instead of using geo queries, I would simply tag content with their  
respective geographical/political attributes. At index time, come up with a  
way to find where each widget shop is located and add an appropriate field.

Geo queries are expensive and are better suited for queries around some  
dynamic point. Your data and queries are primarily static. If you index the  
correct attributes are indexing time, you are only doing the lookup once.

Cheers,

Ivan

On Thu, Sep 5, 2013 at 12:08 PM, [mfriedma@afilias.info](mailto:mfriedma@afilias.info) wrote:

> I'm new to elasticsearch. Thank you for this great product.
> 
> Our client would like to search within a region (continent), or within a  
> country, or even near a city.
> 
> I have been reading about geo shapes etc. I'm trying to find out if there  
> are any predefined shapes.
> 
> Are there predefined shapes for countries and continents within which we  
> would search?
> 
> What strategies would one use to find all of the 'X' within North America  
> for instance? (where X is something like 'Widget shops' and we have all the  
> pins indexed for those shops)
> 
> Many thanks.
> 
> Matt
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Jilles\_van\_Gurp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jilles_van_gurp/32/879_2.png) [@Jilles\_van\_Gurp](https://discuss.elastic.co/u/Jilles_van_Gurp)\
**Post date:** [September 10, 2013, 8:49am UTC](https://discuss.elastic.co/t/geo-search-within-country-or-continent/13481/3 "2013-09-10T08:49:48Z")

</div>

First, if you can simply attach country and state codes to your data set,  
that would be your best option really. That would enable you to use simple  
term queries to do your searches which are about as fast as it gets in ES.

If you can't, you may want to look into getting your hands on a decent data  
set with actual polygons for the areas you are interested in. Your best bet  
for good shapes is quatroshapes. This is a curated dataset by Foursquare  
with polygons for neighborhoods, cities, states, countries. A bit of a  
warning though: this is a very messy dataset. Expect inconsistency, errors,  
and worse.

It comes in the form of shape files; which elasticsearch does not handle  
currently.

To fix that, use a tool called ogr2ogr to convert shape files to geojson.  
Ogr2ogr is part of gdal, which is a set of gis commandline tools.

For example this command converts the quatroshapes neighborhood file while  
also applying a simplification algorithm. You need the latter because ES  
does not handle e.g. self intersecting polygons and several other common  
problems with polygons.

ogr2ogr -wrapdateline -simplify 0.0005 -f geoJSON qs\_neighborhoods.json  
qs\_neighborhoods.shp

Jilles

On Thursday, September 5, 2013 9:08:51 PM UTC+2, mfri...@afilias.info wrote:

> I'm new to elasticsearch. Thank you for this great product.
> 
> Our client would like to search within a region (continent), or within a  
> country, or even near a city.
> 
> I have been reading about geo shapes etc. I'm trying to find out if there  
> are any predefined shapes.
> 
> Are there predefined shapes for countries and continents within which we  
> would search?
> 
> What strategies would one use to find all of the 'X' within North America  
> for instance? (where X is something like 'Widget shops' and we have all the  
> pins indexed for those shops)
> 
> Many thanks.
> 
> Matt

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mfriedma](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mfriedma](https://discuss.elastic.co/u/mfriedma)\
**Post date:** [September 10, 2013, 2:30pm UTC](https://discuss.elastic.co/t/geo-search-within-country-or-continent/13481/4 "2013-09-10T14:30:37Z")

</div>

Very helpful answers. Thank you Ivan and Jilles.  
Cheers, Matt

On Tue, Sep 10, 2013 at 4:49 AM, Jilles van Gurp [jillesvangurp@gmail.com](mailto:jillesvangurp@gmail.com)wrote:

> First, if you can simply attach country and state codes to your data set,  
> that would be your best option really. That would enable you to use simple  
> term queries to do your searches which are about as fast as it gets in ES.
> 
> If you can't, you may want to look into getting your hands on a decent  
> data set with actual polygons for the areas you are interested in. Your  
> best bet for good shapes is quatroshapes. This is a curated dataset by  
> Foursquare with polygons for neighborhoods, cities, states, countries. A  
> bit of a warning though: this is a very messy dataset. Expect  
> inconsistency, errors, and worse.
> 
> It comes in the form of shape files; which elasticsearch does not handle  
> currently.
> 
> To fix that, use a tool called ogr2ogr to convert shape files to geojson.  
> Ogr2ogr is part of gdal, which is a set of gis commandline tools.
> 
> For example this command converts the quatroshapes neighborhood file while  
> also applying a simplification algorithm. You need the latter because ES  
> does not handle e.g. self intersecting polygons and several other common  
> problems with polygons.
> 
> ogr2ogr -wrapdateline -simplify 0.0005 -f geoJSON qs\_neighborhoods.json  
> qs\_neighborhoods.shp
> 
> Jilles
> 
> On Thursday, September 5, 2013 9:08:51 PM UTC+2, mfri...@afilias.infowrote:
> 
> > I'm new to elasticsearch. Thank you for this great product.
> > 
> > Our client would like to search within a region (continent), or within a  
> > country, or even near a city.
> > 
> > I have been reading about geo shapes etc. I'm trying to find out if there  
> > are any predefined shapes.
> > 
> > Are there predefined shapes for countries and continents within which we  
> > would search?
> > 
> > What strategies would one use to find all of the 'X' within North America  
> > for instance? (where X is something like 'Widget shops' and we have all the  
> > pins indexed for those shops)
> > 
> > Many thanks.
> > 
> > Matt
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/R25LFS7Dldk/unsubscribe](https://groups.google.com/d/topic/elasticsearch/R25LFS7Dldk/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:17am UTC](https://discuss.elastic.co/t/geo-search-within-country-or-continent/13481/5 "2017-07-06T02:17:17Z")

</div>


