Find coordinates exist within a polygon map

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.

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.

1 Like
{
  "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.

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

so should i try with geo_polygon?

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:

 GET /myindex_in_2018-04-25/_mapping/ping
1 Like

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