Geo Polygon/Geo Shape query and points on borders (corners)

Yesterday I discovered unexpected ( for me ) behaviour, that seems not documented.

I had try with both types Geo Polygon queries with Geo point data type, and Geo Shape query with Geo Shape type "point", but results are the same.

So the problem is, that queries not returning points that are on the borders or, as example, on corners of polygon. I don't found any information about this in documentation, and by scripts was based on attaching points outside polygons to edges - so in the end I had wrong results.

Some basic example with Geo Shape:

PUT geo_shapes_test
{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "properties" : {
            "location" : { "type" : "geo_shape" }
        }
    }
}

PUT geo_shapes_test/_doc/1
{
  "location": {
    "type": "point",
    "coordinates": [1.0,1.0]
  }
}

# FAIL - point on corner
GET geo_shapes_test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "filter": {
        "geo_shape": {
          "location": {
            "shape": {
              "type": "polygon",
              "coordinates": [
                [
                  [
                    1.0,
                    1.0
                  ],
                  [
                    1.0,
                    3.0
                  ],
                  [
                    4.0,
                    3.0
                  ],
                  [
                    4.0,
                    1.0
                  ],
                  [
                    1.0,
                    1.0
                  ]
                ]
              ]
            },
            "relation": "within"
          }
        }
      }
    }
  }
}

# FAIL - 8 digits after point
GET geo_shapes_test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "filter": {
        "geo_shape": {
          "location": {
            "shape": {
              "type": "polygon",
              "coordinates": [
                [
                  [
                    0.99999999,
                    0.99999999
                  ],
                  [
                    0.99999999,
                    3.00000001
                  ],
                  [
                    4.00000001,
                    3.00000001
                  ],
                  [
                    4.00000001,
                    0.99999999
                  ],
                  [
                    0.99999999,
                    0.99999999
                  ]
                ]
              ]
            },
            "relation": "within"
          }
        }
      }
    }
  }
}

# OK - 7 digits after point
GET geo_shapes_test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "filter": {
        "geo_shape": {
          "location": {
            "shape": {
              "type": "polygon",
              "coordinates": [
                [
                  [
                    0.9999999,
                    0.9999999
                  ],
                  [
                    0.9999999,
                    3.0000001
                  ],
                  [
                    4.0000001,
                    3.0000001
                  ],
                  [
                    4.0000001,
                    0.9999999
                  ],
                  [
                    0.9999999,
                    0.9999999
                  ]
                ]
              ]
            },
            "relation": "within"
          }
        }
      }
    }
  }
}

Here we can see that if we making polygon bigger (for 7 digits after point) it will return point. But 8 digits will fail.

I think this issue must be or investigated, or added as a note to documentation. Because it is quite unpredictable.

Thank you.

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