# Searching for geo\_circles as geo\_shapes

**URL:** <https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719>\
**Category:** Elasticsearch\
**Created:** [March 31, 2014, 5:34pm UTC](https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719 "2014-03-31T17:34:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Viktor\_Nordling](https://avatars.discourse-cdn.com/v4/letter/v/a3d4f5/32.png) [@Viktor\_Nordling](https://discuss.elastic.co/u/Viktor_Nordling)\
**Post date:** [March 31, 2014, 5:34pm UTC](https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719/1 "2014-03-31T17:34:51Z")

</div>

This commit[https://github.com/elasticsearch/elasticsearch/commit/0c2d12bda34fbbe0ffd3cef5140f5d5a3919b080](https://github.com/elasticsearch/elasticsearch/commit/0c2d12bda34fbbe0ffd3cef5140f5d5a3919b080)adds support for indexing circles as geo\_shapes, which is something I'd  
like to do (rather than approximating circles with polygons).

However, searching for intersection between a point and a circle (is this  
point in a circle) doesn't seem to work. Checking if a point is in a  
polygon can be done like this:

POST polygons/\_search  
{  
"size" : 1000000,  
"query" : {  
"terms" : {  
"\_id" : ["GKN\_32UnRiylOsYwyltX4g"]  
}  
},  
"post\_filter" : {  
"geo\_shape" : {  
"vertices" : {  
"shape" : {  
"type" : "point",  
"coordinates" : [150, -30]  
},  
"relation" : "intersects"  
}  
}  
}  
}

So that will check if the point (150, -30) is in the polygon with the id  
GKN.. But if the "polygon" is instead a circle, I don't get any hits  
(regardless of how big I make the circle). Since the search is for a  
geo\_shape and got a geo\_circle and a geo\_polygon are geo\_shapes, it seems  
like this should work.

What am I missing?

Thanks.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/26c71961-0dde-4416-80ea-2687a85a5b19%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/26c71961-0dde-4416-80ea-2687a85a5b19%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [March 31, 2014, 5:46pm UTC](https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719/2 "2014-03-31T17:46:17Z")

</div>

It's my impression, and indeed experience, that searching a distance from a  
geo\_point means that the distance is a radius, and therefore the search is  
a circular shape. No need for an explicit shape: A circle is nothing more  
than a distance from a point.

Regards,  
Brian

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/401fe81d-9f39-4e30-ac98-1f6d4d2b6e91%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/401fe81d-9f39-4e30-ac98-1f6d4d2b6e91%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Viktor\_Nordling](https://avatars.discourse-cdn.com/v4/letter/v/a3d4f5/32.png) [@Viktor\_Nordling](https://discuss.elastic.co/u/Viktor_Nordling)\
**Post date:** [April 9, 2014, 10:39am UTC](https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719/3 "2014-04-09T10:39:28Z")

</div>

So here's my use case: say that you have 50 points, with _different_ radii.

A new point is added and I want to check, is this point within any of the  
other 50 circles. I can't do just a search for a distance, because there's  
no one distance to search for. Does that make sense?

On Tuesday, 1 April 2014 04:46:17 UTC+11, InquiringMind wrote:

> It's my impression, and indeed experience, that searching a distance from  
> a geo\_point means that the distance is a radius, and therefore the search  
> is a circular shape. No need for an explicit shape: A circle is nothing  
> more than a distance from a point.
> 
> Regards,  
> Brian

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2a24cfc4-6946-4ff7-a5b6-cb6078e080f7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2a24cfc4-6946-4ff7-a5b6-cb6078e080f7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 9, 2014, 11:03am UTC](https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719/4 "2014-04-09T11:03:00Z")

</div>

Hey,

can you create a complete example, including mapping, indexing and  
searching, so one can reproduce locally?

--Alex

On Wed, Apr 9, 2014 at 12:39 PM, Viktor Nordling  
[viktor.nordling@gmail.com](mailto:viktor.nordling@gmail.com)wrote:

> So here's my use case: say that you have 50 points, with _different_ radii.
> 
> A new point is added and I want to check, is this point within any of the  
> other 50 circles. I can't do just a search for a distance, because there's  
> no one distance to search for. Does that make sense?
> 
> On Tuesday, 1 April 2014 04:46:17 UTC+11, InquiringMind wrote:
> 
> > It's my impression, and indeed experience, that searching a distance from  
> > a geo\_point means that the distance is a radius, and therefore the search  
> > is a circular shape. No need for an explicit shape: A circle is nothing  
> > more than a distance from a point.
> > 
> > Regards,  
> > Brian
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/2a24cfc4-6946-4ff7-a5b6-cb6078e080f7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2a24cfc4-6946-4ff7-a5b6-cb6078e080f7%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/2a24cfc4-6946-4ff7-a5b6-cb6078e080f7%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/2a24cfc4-6946-4ff7-a5b6-cb6078e080f7%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM\_ehbfeQdxkxWC-dhMmp903kdBVE0DDZyH%3DiH5%2BNVGtLw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_ehbfeQdxkxWC-dhMmp903kdBVE0DDZyH%3DiH5%2BNVGtLw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ubazu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ubazu/32/1417_2.png) [@ubazu](https://discuss.elastic.co/u/ubazu)\
**Post date:** [July 9, 2014, 4:26pm UTC](https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719/5 "2014-07-09T16:26:16Z")

</div>

I am having the same problem with the search all assets that have a circle that intersects a point. Did somebody have a solution to this?

---

<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:** [July 10, 2014, 2:38pm UTC](https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719/6 "2014-07-10T14:38:12Z")

</div>

I have a bit of code in my geogeometry project that converts circles to  
polygons with whatever number of segments you wish:  
[https://github.com/jillesvangurp/geogeometry/blob/master/src/main/java/com/jillesvangurp/geo/GeoGeometry.java](https://github.com/jillesvangurp/geogeometry/blob/master/src/main/java/com/jillesvangurp/geo/GeoGeometry.java).  
A few dozen gives you a really nice approximation of a circle typically.

Look for the circle2polygon method. It's in Java but it's quite easy to  
convert it to other languages since it is a simple static method. Using  
that you should be able to use the geo\_shape query to do intersects queries  
on es. Would actually be nice if they added support for circles using  
something like this. I guess the main issue is figuring out how many  
segments you need on the circle.

Jilles

On Thursday, July 10, 2014 10:51:03 AM UTC+2, Silviu Rosu wrote:

> I am having the same problem with the search all assets that have a circle  
> that intersects a point. Did somebody have a solution to this?
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Searching-for-geo-circles-as-geo-shapes-tp4053167p4059531.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-for-geo-circles-as-geo-shapes-tp4053167p4059531.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7daed3d6-5562-4ba5-b741-4cd17d0c27ed%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7daed3d6-5562-4ba5-b741-4cd17d0c27ed%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Viktor\_Nordling](https://avatars.discourse-cdn.com/v4/letter/v/a3d4f5/32.png) [@Viktor\_Nordling](https://discuss.elastic.co/u/Viktor_Nordling)\
**Post date:** [October 4, 2014, 2:23am UTC](https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719/7 "2014-10-04T02:23:51Z")

</div>

@Silviu, sorry I never got around to submitting a "complete example,  
including mapping, indexing and searching" and instead worked around it  
with polygons. If you have the energy it would be great to get that example  
submitted.

Cheers,  
Viktor

On Friday, 11 July 2014 00:38:12 UTC+10, Jilles van Gurp wrote:

> I have a bit of code in my geogeometry project that converts circles to  
> polygons with whatever number of segments you wish:  
> [https://github.com/jillesvangurp/geogeometry/blob/master/src/main/java/com/jillesvangurp/geo/GeoGeometry.java](https://github.com/jillesvangurp/geogeometry/blob/master/src/main/java/com/jillesvangurp/geo/GeoGeometry.java).  
> A few dozen gives you a really nice approximation of a circle typically.
> 
> Look for the circle2polygon method. It's in Java but it's quite easy to  
> convert it to other languages since it is a simple static method. Using  
> that you should be able to use the geo\_shape query to do intersects queries  
> on es. Would actually be nice if they added support for circles using  
> something like this. I guess the main issue is figuring out how many  
> segments you need on the circle.
> 
> Jilles
> 
> On Thursday, July 10, 2014 10:51:03 AM UTC+2, Silviu Rosu wrote:
> 
> > I am having the same problem with the search all assets that have a  
> > circle  
> > that intersects a point. Did somebody have a solution to this?
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/Searching-for-geo-circles-as-geo-shapes-tp4053167p4059531.html](http://elasticsearch-users.115913.n3.nabble.com/Searching-for-geo-circles-as-geo-shapes-tp4053167p4059531.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e0ae41fa-a84f-414b-818f-995531d2bf61%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e0ae41fa-a84f-414b-818f-995531d2bf61%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:58am UTC](https://discuss.elastic.co/t/searching-for-geo-circles-as-geo-shapes/16719/8 "2017-07-06T00:58:18Z")

</div>


