# Distance from a point to a Polygon

**URL:** <https://discuss.elastic.co/t/distance-from-a-point-to-a-polygon/176452>\
**Category:** Elasticsearch\
**Created:** [April 11, 2019, 4:23pm UTC](https://discuss.elastic.co/t/distance-from-a-point-to-a-polygon/176452 "2019-04-11T16:23:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fgabay](https://avatars.discourse-cdn.com/v4/letter/f/73ab20/32.png) [@fgabay](https://discuss.elastic.co/u/fgabay)\
**Post date:** [April 11, 2019, 4:23pm UTC](https://discuss.elastic.co/t/distance-from-a-point-to-a-polygon/176452/1 "2019-04-11T16:23:40Z")

</div>

How to perform a distance filter from a point to a polygon and specify that the distance should be less than or equal to a field from the index ?

Something like the example

GET /my\_locations/\_search  
{  
"query": {  
"bool" : {  
"must" : {  
"match\_all" : {}  
},  
"filter" : {  
"geo\_distance" : {  
"distance" : " **a field from the index**",  
"pin.location" : {  
"pin.location" : [-70, 40], [-90, 50] [...], [...]  
}  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 11, 2019, 6:58pm UTC](https://discuss.elastic.co/t/distance-from-a-point-to-a-polygon/176452/2 "2019-04-11T18:58:19Z")

</div>

You need to run 2 separate queries.

---

<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:** [May 9, 2019, 6:58pm UTC](https://discuss.elastic.co/t/distance-from-a-point-to-a-polygon/176452/3 "2019-05-09T18:58:24Z")

</div>

Closed on May 9, 2019, 6:58pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
