# Geo\_Polygon q's

**URL:** <https://discuss.elastic.co/t/geo-polygon-qs/5924>\
**Category:** Elasticsearch\
**Created:** [November 21, 2011, 2:11pm UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924 "2011-11-21T14:11:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Estrada](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_estrada/32/2704_2.png) [@Adam\_Estrada](https://discuss.elastic.co/u/Adam_Estrada)\
**Post date:** [November 21, 2011, 2:11pm UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924/1 "2011-11-21T14:11:16Z")

</div>

All,

I am trying to perform some benchmark testing on ES to see if I can find  
all the points that fall within a polygon AND beat PostGIS. I am having  
some trouble getting my query to work and would like to bounce some of it  
off this list. Here is how I am running my tests.

1. Load all of the Geonames data in to ES. There are 7.8 million points  
all over the world so I figure this would be a good use case. The schema  
looks like this. [http://pastebin.com/GbVDjEMi](http://pastebin.com/GbVDjEMi)
2. Next, I extracted all the polygons for each country in the world. You  
can find the data here:  
[http://ogr2elasticsearch.googlecode.com/files/polygons.zip](http://ogr2elasticsearch.googlecode.com/files/polygons.zip)
3. Finally, I build up my query like this. [http://pastebin.com/dMFeYeSJ](http://pastebin.com/dMFeYeSJ) The  
problem is that nothing happens and I don't know if it's because the query  
is wrong or if ES just can't handle that many points.

Any help on this would be greatly appreciated. I will post the full  
workflow and results once I am done with this.

Regards,

Adam

---

<div class="post-metadata">

**Author:** ![Adam\_Estrada](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_estrada/32/2704_2.png) [@Adam\_Estrada](https://discuss.elastic.co/u/Adam_Estrada)\
**Post date:** [November 21, 2011, 2:30pm UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924/2 "2011-11-21T14:30:23Z")

</div>

I realize that when I copied the query text in to Pastebin, "coordinates"  
was misspelled. It still does not work though.

Adam

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 21, 2011, 2:37pm UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924/3 "2011-11-21T14:37:05Z")

</div>

Hiya Adam

> ```
> 1. Finally, I build up my query like this.
> http://pastebin.com/dMFeYeSJ The problem is that nothing
> happens and I don't know if it's because the query is wrong or
> if ES just can't handle that many points.
> 
> ```

Have you tried using 'points' instead of 'coordinates'?

> **[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.

clint

---

<div class="post-metadata">

**Author:** ![Adam\_Estrada](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_estrada/32/2704_2.png) [@Adam\_Estrada](https://discuss.elastic.co/u/Adam_Estrada)\
**Post date:** [November 21, 2011, 2:57pm UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924/4 "2011-11-21T14:57:47Z")

</div>

Hmmm...Now I seem to be getting an error that it does not like the element  
[filtered] [http://pastebin.com/sZdMvnRa](http://pastebin.com/sZdMvnRa)

Adam

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 21, 2011, 3:21pm UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924/5 "2011-11-21T15:21:55Z")

</div>

On Mon, 2011-11-21 at 06:57 -0800, Adam Estrada wrote:

> Hmmm...Now I seem to be getting an error that it does not like the  
> element [filtered] [[2011-11-21 09:54:35,974][DEBUG][action.search.type] [Anole] [geonames][2 - Pastebin.com](http://pastebin.com/sZdMvnRa)

{ query: { filtered: { query: {...}, filter: {...} }}}

clint

> Adam

---

<div class="post-metadata">

**Author:** ![Adam\_Estrada](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_estrada/32/2704_2.png) [@Adam\_Estrada](https://discuss.elastic.co/u/Adam_Estrada)\
**Post date:** [November 21, 2011, 4:21pm UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924/6 "2011-11-21T16:21:13Z")

</div>

Got it! I was missing the opening "query" node. Looks like with my  
preliminary queries are about 2 times slower than with a spatial database.

Adam

---

<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:** [November 21, 2011, 6:51pm UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924/7 "2011-11-21T18:51:36Z")

</div>

Can you "wrap it" in a bounding box filter and then do the polygon?  
Wrapping it can be using an "and" filter, with the bounding box as the  
first filter, and the polygon as the second. Note that bounding box filter  
can work on indexed lat lon, or in memory checks.

On Mon, Nov 21, 2011 at 6:21 PM, Adam Estrada [estrada.adam@gmail.com](mailto:estrada.adam@gmail.com)wrote:

> Got it! I was missing the opening "query" node. Looks like with my  
> preliminary queries are about 2 times slower than with a spatial database.
> 
> Adam

---

<div class="post-metadata">

**Author:** ![Adam\_Estrada](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_estrada/32/2704_2.png) [@Adam\_Estrada](https://discuss.elastic.co/u/Adam_Estrada)\
**Post date:** [December 2, 2011, 10:23pm UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924/8 "2011-12-02T22:23:13Z")

</div>

@kimchy,

Do you have any comments on this?

> <https://github.com/elastic/elasticsearch/issues/1486>

Adam

---

<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:46am UTC](https://discuss.elastic.co/t/geo-polygon-qs/5924/9 "2017-07-06T03:46:34Z")

</div>


