Failed to create valid geo_shape

Appreciate if someone can shed some light on why ES complains about the seemingly valid geo_shape I'm trying to create.

The question has been asked on SO (Discuss whined about the length of the body)

Thank you very much in advance

The message is opaque, granted, but I think it will be a problem that this point is repeated so that this shape is self-intersecting.

[-116.96965590466098, 32.65769347876227]

The shape is really an outline with a hole, and if you represent it as such a shape then it seems to index ok:

1 Like

Thanks @DavidTurner, I was going to update the post with another observation that goes in the same direction as yours, i.e. that all other polygons that also exhibit the same issue are concave polygons whose path contains two identical points (except the first and last) that are not following each other, which indeed creates a hole.

I wasn't aware of anything in the GeoJson spec that prevents self-intersecting polygons (at least nothing that mapbox/geojsonhint complains about), but that might explain the issue. I think the error message could be less opaque, indeed.

It's possible that this is permitted by GeoJSON. Nonetheless I think the response could be better so I opened https://github.com/elastic/elasticsearch/issues/40998.

1 Like

Thanks @DavidTurner, much appreciated!

@DavidTurner here is another interesting one with another error message that seems intuitive at first, but isn't when you look at the shape:

PUT index/doc/1630656
{
  "parcel": {
    "type": "Polygon",
    "coordinates": [
      [
        [
          -122.64482060784113,
          38.56711793465956
        ],
        [
          -122.64494911515231,
          38.56806649867188
        ],
        [
          -122.64646104699145,
          38.569267483716594
        ],
        [
          -122.64665226614191,
          38.56929059387256
        ],
        [
          -122.64662994320358,
          38.56928589940636
        ],
        [
          -122.64668841957221,
          38.5692949639317
        ],
        [
          -122.64665226614191,
          38.56929059387256
        ],
        [
          -122.64675499746104,
          38.56931222105709
        ],
        [
          -122.64687327352003,
          38.56935284573999
        ],
        [
          -122.64692832584761,
          38.56936744190402
        ],
        [
          -122.64698558991063,
          38.569375184019115
        ],
        [
          -122.64704369004176,
          38.569375886094306
        ],
        [
          -122.64710123048759,
          38.56936953126357
        ],
        [
          -122.6471568289413,
          38.56935627219081
        ],
        [
          -122.64724333535125,
          38.56934103930251
        ],
        [
          -122.64733109987546,
          38.569331195304905
        ],
        [
          -122.64741957872974,
          38.5693268011908
        ],
        [
          -122.64750822370347,
          38.5693278841858
        ],
        [
          -122.64759648555793,
          38.56933443757932
        ],
        [
          -122.64768381742691,
          38.569346420767744
        ],
        [
          -122.6477696782066,
          38.56936375950291
        ],
        [
          -122.64784262002463,
          38.56937339405759
        ],
        [
          -122.64791649753268,
          38.56937624952554
        ],
        [
          -122.64799029207013,
          38.56937228653462
        ],
        [
          -122.64806298612233,
          38.569361559728456
        ],
        [
          -122.64813357734766,
          38.56934421701336
        ],
        [
          -122.6481796239189,
          38.56932949668995
        ],
        [
          -122.64822706056755,
          38.56931780933501
        ],
        [
          -122.64827556379203,
          38.56930923465239
        ],
        [
          -122.64691737383271,
          38.56652470841123
        ],
        [
          -122.64482060784113,
          38.56711793465956
        ]
      ]
    ]
  }
} 

The shape looks like this (no intersection and shape is closed)

The error message now says:

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse field [parcel] of type [geo_shape]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse field [parcel] of type [geo_shape]",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "first and last points of the polygon must be the same (it must close itself): polyLats[0]=38.56806649867188 polyLats[4]=38.56935284573999"
    }
  },
  "status": 400
}

From all the points in the coordinates array, ES seems to have only kept 5 since it's comparing point 0 with point 4, which are in reality the second, respectively the ninth of the polygon array given in input.

Appreciate if you have any idea why this happens.

Never mind, again data quality seems to be responsible for this. There are overlapping points at the top right of the figure (points, 5, 6, 7), which might explain the issue.

yes, it seems there is a loop in one side:

The error is misleading because in those cases the logic tries to incorrectly divide the polygon into two components. One of the components becomes invalid.

Thank you @Ignacio_Vera, shall I file an issue to improve the message as David did for the earlier issue?

If you don't mind, yes so we keep track of this issues.

Actually, it's the same type of shape as the very first one, i.e. a hole that touches the outline. Yet, the error message is different.

PUT index/doc/1
{
  "parcel": {
    "type": "Polygon",
    "coordinates": [
      [
        [
          0,
          0
        ],
        [
          0,
          2
        ],
        [
          1,
          1.9
        ],
        [
          0.5,
          1.8
        ],
        [
          1.5,
          1.8
        ],
        [
          1,
          1.9
        ],
        [
          2,
          2
        ],
        [
          2,
          0
        ],
        [
          0,
          0
        ]
      ]
    ]
  }
}

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