Elastic Search geo shape query not working

346 Views Asked by At

I have a polygon and 2 points. The polygon is a Elastic Search document (where the location fields has a "polygon" type)

I'm running a query to figure rather or not these 2 points are inside this polygon:

enter image description here

enter image description here

enter image description here

The polygon is in grey and the 2 points are the green and red markers. We can clearly see that the 2 markers are not inside the polygon.

I'm running the following Elastic Search query for each marker to check rather or not they are inside the polygon:

Red Marker:

{
  "query": {
    "bool": {
      "filter": [
        {
          "geo_shape": {
            "location": {
              "shape": {
                "type": "point",
                "coordinates": [
                  104.15026187896727,
                  15.804270203162801
                ]
              }
            }
          }
        }
      ]
    }
  }
}

=====> One result

Green Marker:

{
  "query": {
    "bool": {
      "filter": [
        {
          "geo_shape": {
            "location": {
              "shape": {
                "type": "point",
                "coordinates": [
                  104.1529,
                  15.8060
                ]
              }
            }
          }
        }
      ]
    }
  }
}

=====> No result

So it's correct for the Green Marker (no result, it means the marker is outside the polygon), and it's not correct for the Red Marker (One result, it means the the marker is inside the polygon)

How come it is not correct for the Red Marker?

0

There are 0 best solutions below