# Find coordinates exist within a polygon map

**URL:** <https://discuss.elastic.co/t/find-coordinates-exist-within-a-polygon-map/154126>\
**Category:** Elasticsearch\
**Created:** [October 26, 2018, 7:24am UTC](https://discuss.elastic.co/t/find-coordinates-exist-within-a-polygon-map/154126 "2018-10-26T07:24:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![inandi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inandi/32/40801_2.png) [@inandi](https://discuss.elastic.co/u/inandi)\
**Post date:** [October 26, 2018, 7:24am UTC](https://discuss.elastic.co/t/find-coordinates-exist-within-a-polygon-map/154126/1 "2018-10-26T07:24:45Z")

</div>

suppose my ES has 10 coordinates stored. now I have drawn a shape which coordinates points are A, B, C, D. Now Es had 10 coordinates, 2 of them are inside this shape. **need a ES query to get those coordinates**. is it possible or I am expecting something terribly wrong.

 ![drawisland](https://us1.discourse-cdn.com/elastic/original/3X/4/e/4e8f16a66d41d4785e3ddfac406ee6f804444827.jpeg)

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [October 26, 2018, 10:08am UTC](https://discuss.elastic.co/t/find-coordinates-exist-within-a-polygon-map/154126/2 "2018-10-26T10:08:34Z")

</div>

Are those coordinates in different documents or in one document?

If they are in different documents and they have been indexed as `geo_point`, a `geo_polygon` query should do the trick.

---

<div class="post-metadata">

**Author:** ![inandi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inandi/32/40801_2.png) [@inandi](https://discuss.elastic.co/u/inandi)\
**Post date:** [October 26, 2018, 11:25am UTC](https://discuss.elastic.co/t/find-coordinates-exist-within-a-polygon-map/154126/3 "2018-10-26T11:25:03Z")

</div>

```
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 2,
    "successful": 2,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 7,
    "max_score": 1,
    "hits": [
      {
        "_index": "myindex_in_2018-04-25",
        "_type": "ping",
        "_id": "HCmxrmYBWVZLOyhURbA8",
        "_score": 1,
        "_source": {
          "idfa": "CA42A60D-558A-4443-8B88-57D1C3C3BD0D",
          "index_day": "2018-04-25",
          "ideditor": "6",
          "country": "UK",
          "geo_type": "GPS_LOCATION",
          "location": {
            "lat": "12.9716",
            "lon": "77.5946"
          },
          "happenon": 1524635328,
          "idapp": "81"
        }
      },
      {
        "_index": "myindex_in_2018-04-25",
        "_type": "ping",
        "_id": "SoEDq2YBpuZqXHIB-p-n",
        "_score": 1,
        "_source": {
          "ideditor": "6",
          "index_day": "2018-04-25",
          "happenon": 1524635328,
          "idapp": "81",
          "geo_type": "GPS_LOCATION",
          "idfa": "CA42A60D-558A-4443-8B88-57D1C3C3BD0D",
          "country": "UK",
          "location": {
            "lat": "48.68",
            "lon": "1.7557"
          }
        }
      },
      {
        "_index": "myindex_in_2018-04-25",
        "_type": "ping",
        "_id": "PDVlq2YBrZ3Ols02ZNlo",
        "_score": 1,
        "_source": {
          "geo_type": "GPS_LOCATION",
          "happenon": 1524635328,
          "location": {
            "lat": "17.9716",
            "lon": "57.5946"
          },
          "idapp": "81",
          "ideditor": "6",
          "country": "UK",
          "index_day": "2018-04-25",
          "idfa": "CA42A60D-558A-4443-8B88-57D1C3C3BD0D"
        }
      },
    ]
  }
}

```

SAMPLE DATA. **indexes are dynamic but type is fixed.(ping)**  
THANK YOU FOR YOUR REPLY.

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [October 26, 2018, 11:56am UTC](https://discuss.elastic.co/t/find-coordinates-exist-within-a-polygon-map/154126/4 "2018-10-26T11:56:34Z")

</div>

The only thing to mind here is that polygons are not geodesic.

---

<div class="post-metadata">

**Author:** ![inandi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inandi/32/40801_2.png) [@inandi](https://discuss.elastic.co/u/inandi)\
**Post date:** [October 26, 2018, 11:57am UTC](https://discuss.elastic.co/t/find-coordinates-exist-within-a-polygon-map/154126/5 "2018-10-26T11:57:59Z")

</div>

> [@Ignacio\_Vera](#):
>
> polygons are not geodesic

so should i try with geo\_polygon?

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [October 26, 2018, 12:05pm UTC](https://discuss.elastic.co/t/find-coordinates-exist-within-a-polygon-map/154126/6 "2018-10-26T12:05:32Z")

</div>

Yes, but you need to make sure that the field `location` is mapped to a geo\_point.

you can get the current mapping with the command:

```auto
 GET /myindex_in_2018-04-25/_mapping/ping

```

---

<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:** [November 23, 2018, 12:05pm UTC](https://discuss.elastic.co/t/find-coordinates-exist-within-a-polygon-map/154126/7 "2018-11-23T12:05:32Z")

</div>

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