# Working example for geo polygon search with the Java API?

**URL:** <https://discuss.elastic.co/t/working-example-for-geo-polygon-search-with-the-java-api/6963>\
**Category:** Elasticsearch\
**Created:** [March 9, 2012, 11:04pm UTC](https://discuss.elastic.co/t/working-example-for-geo-polygon-search-with-the-java-api/6963 "2012-03-09T23:04:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugen\_Paraschiv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugen_paraschiv/32/919_2.png) [@Eugen\_Paraschiv](https://discuss.elastic.co/u/Eugen_Paraschiv)\
**Post date:** [March 9, 2012, 11:04pm UTC](https://discuss.elastic.co/t/working-example-for-geo-polygon-search-with-the-java-api/6963/1 "2012-03-09T23:04:50Z")

</div>

Hi,  
I'm working on a geo spatial polygon based search and I'm trying to use the  
Java API; is there any example/test that I could use as a starting point,  
already doing this?  
Thanks.

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [March 12, 2012, 1:42am UTC](https://discuss.elastic.co/t/working-example-for-geo-polygon-search-with-the-java-api/6963/2 "2012-03-12T01:42:08Z")

</div>

On Mar 9, 3:04 pm, Eugen Paraschiv [hanrisel...@gmail.com](mailto:hanrisel...@gmail.com) wrote:

> I'm working on a geo spatial polygon based search and I'm trying to use the  
> Java API; is there any example/test that I could use as a starting point,  
> already doing this?

I haven't used the polygon search feature, but assume you'd use it  
like so:

FilterBuilder filter = FilterBuilders.geoPolygonFilter(filterName)  
.addPoint(lat1, lon1).addPoint(lat2, lon2).addPoint(lat3, lon3);  
QueryBuilder query = QueryBuilders.constantScoreQuery(filter);  
SearchSourceBuilder source = new SearchSourceBuilder().query(query);  
SearchRequest request =  
Requests.searchRequest(indexName).source(source);  
...

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [March 13, 2012, 8:50pm UTC](https://discuss.elastic.co/t/working-example-for-geo-polygon-search-with-the-java-api/6963/3 "2012-03-13T20:50:27Z")

</div>

On Tue, Mar 13, 2012 at 12:12, Eugen Paraschiv [hanriseldon@gmail.com](mailto:hanriseldon@gmail.com)  
wrote:

> Am I perhaps missing something or doing something wrong. Is there an  
> integration test that verifies the polygon search functionality?

I just tested this by replacing a geoBoundingBoxFilter with a  
geoPolygonFilter (with 4 points), and it appears to work.

Can you post a complete test case? Do other queries (e.g. bounding box  
or exact match) return results? May need to flush the index or wait a  
short while...

---

<div class="post-metadata">

**Author:** ![Eugen\_Paraschiv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugen_paraschiv/32/919_2.png) [@Eugen\_Paraschiv](https://discuss.elastic.co/u/Eugen_Paraschiv)\
**Post date:** [March 14, 2012, 9:00am UTC](https://discuss.elastic.co/t/working-example-for-geo-polygon-search-with-the-java-api/6963/4 "2012-03-14T09:00:10Z")

</div>

OK, I'll start with that test and work my way towards polygon.  
Thanks.  
Eugen.

On Tue, Mar 13, 2012 at 10:50 PM, Eric Jain [eric.jain@gmail.com](mailto:eric.jain@gmail.com) wrote:

> On Tue, Mar 13, 2012 at 12:12, Eugen Paraschiv [hanriseldon@gmail.com](mailto:hanriseldon@gmail.com)  
> wrote:
> 
> > Am I perhaps missing something or doing something wrong. Is there an  
> > integration test that verifies the polygon search functionality?
> 
> I just tested this by replacing a geoBoundingBoxFilter with a  
> geoPolygonFilter (with 4 points), and it appears to work.
> 
> Can you post a complete test case? Do other queries (e.g. bounding box  
> or exact match) return results? May need to flush the index or wait a  
> short while...

---

<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:36am UTC](https://discuss.elastic.co/t/working-example-for-geo-polygon-search-with-the-java-api/6963/5 "2017-07-06T03:36:17Z")

</div>


