**Build scan:**
https://gradle-enterprise.elastic.co/s/p7n7etkicebme/tests/:x-pack:plugin:spatial:internalClusterTest/org.elasticsearch.xpack.spatial.search.CartesianShapeQueryTests/testQueryRandomGeoCollection

**Reproduction line:**
`./gradlew ':x-pack:plugin:spatial:internalClusterTest' --tests "org.elasticsearch.xpack.spatial.search.CartesianShapeQueryTests.testQueryRandomGeoCollection" -Dtests.seed=D42035A03986D727 -Dtests.locale=lt -Dtests.timezone=Asia/Baku -Druntime.java=17`

**Applicable branches:**
master

**Reproduces locally?:**
No

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.xpack.spatial.search.CartesianShapeQueryTests&tests.test=testQueryRandomGeoCollection

**Failure excerpt:**
```
org.elasticsearch.index.mapper.MapperParsingException: failed to parse field [geo] of type [shape]

  at __randomizedtesting.SeedInfo.seed([D42035A03986D727:CCF71E7B64748804]:0)
  at org.elasticsearch.index.mapper.AbstractGeometryFieldMapper.lambda$parse$1(AbstractGeometryFieldMapper.java:191)
  at org.elasticsearch.xpack.spatial.index.mapper.ShapeParser.parse(ShapeParser.java:40)
  at org.elasticsearch.index.mapper.AbstractGeometryFieldMapper.parse(AbstractGeometryFieldMapper.java:187)
  at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:409)
  at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:461)
  at org.elasticsearch.index.mapper.DocumentParser.innerParseObject(DocumentParser.java:313)
  at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrNested(DocumentParser.java:278)
  at org.elasticsearch.index.mapper.DocumentParser.internalParseDocument(DocumentParser.java:127)
  at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:79)
  at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:78)
  at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:999)
  at org.elasticsearch.index.shard.IndexShard.applyIndexOperation(IndexShard.java:948)
  at org.elasticsearch.index.shard.IndexShard.applyIndexOperationOnPrimary(IndexShard.java:892)
  at org.elasticsearch.action.bulk.TransportShardBulkAction.executeBulkItemRequest(TransportShardBulkAction.java:321)
  at org.elasticsearch.action.bulk.TransportShardBulkAction$2.doRun(TransportShardBulkAction.java:187)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
  at org.elasticsearch.action.bulk.TransportShardBulkAction.performOnPrimary(TransportShardBulkAction.java:253)
  at org.elasticsearch.action.bulk.TransportShardBulkAction.dispatchedShardOperationOnPrimary(TransportShardBulkAction.java:133)
  at org.elasticsearch.action.bulk.TransportShardBulkAction.dispatchedShardOperationOnPrimary(TransportShardBulkAction.java:72)
  at org.elasticsearch.action.support.replication.TransportWriteAction$1.doRun(TransportWriteAction.java:211)
  at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:769)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
  at java.lang.Thread.run(Thread.java:833)

  Caused by: java.lang.IllegalArgumentException: at least three non-collinear points required

    at org.apache.lucene.geo.Tessellator.tessellate(Tessellator.java:174)
    at org.apache.lucene.geo.Tessellator.tessellate(Tessellator.java:152)
    at org.apache.lucene.document.XYShape.createIndexableFields(XYShape.java:83)
    at org.apache.lucene.document.XYShape.createIndexableFields(XYShape.java:72)
    at org.elasticsearch.xpack.spatial.index.mapper.CartesianShapeIndexer$LuceneGeometryVisitor.visit(CartesianShapeIndexer.java:114)
    at org.elasticsearch.xpack.spatial.index.mapper.CartesianShapeIndexer$LuceneGeometryVisitor.visit(CartesianShapeIndexer.java:50)
    at org.elasticsearch.geometry.Polygon.visit(Polygon.java:84)
    at org.elasticsearch.xpack.spatial.index.mapper.CartesianShapeIndexer$LuceneGeometryVisitor.visit(CartesianShapeIndexer.java:66)
    at org.elasticsearch.xpack.spatial.index.mapper.CartesianShapeIndexer$LuceneGeometryVisitor.visit(CartesianShapeIndexer.java:50)
    at org.elasticsearch.geometry.GeometryCollection.visit(GeometryCollection.java:51)
    at org.elasticsearch.xpack.spatial.index.mapper.CartesianShapeIndexer.indexShape(CartesianShapeIndexer.java:46)
    at org.elasticsearch.xpack.spatial.index.mapper.ShapeFieldMapper.index(ShapeFieldMapper.java:187)
    at org.elasticsearch.xpack.spatial.index.mapper.ShapeFieldMapper.index(ShapeFieldMapper.java:52)
    at org.elasticsearch.index.mapper.AbstractGeometryFieldMapper.lambda$parse$0(AbstractGeometryFieldMapper.java:187)
    at org.elasticsearch.xpack.spatial.index.mapper.ShapeParser.parse(ShapeParser.java:37)
    at org.elasticsearch.index.mapper.AbstractGeometryFieldMapper.parse(AbstractGeometryFieldMapper.java:187)
    at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:409)
    at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:461)
    at org.elasticsearch.index.mapper.DocumentParser.innerParseObject(DocumentParser.java:313)
    at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrNested(DocumentParser.java:278)
    at org.elasticsearch.index.mapper.DocumentParser.internalParseDocument(DocumentParser.java:127)
    at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:79)
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:78)
    at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:999)
    at org.elasticsearch.index.shard.IndexShard.applyIndexOperation(IndexShard.java:948)
    at org.elasticsearch.index.shard.IndexShard.applyIndexOperationOnPrimary(IndexShard.java:892)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.executeBulkItemRequest(TransportShardBulkAction.java:321)
    at org.elasticsearch.action.bulk.TransportShardBulkAction$2.doRun(TransportShardBulkAction.java:187)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.performOnPrimary(TransportShardBulkAction.java:253)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.dispatchedShardOperationOnPrimary(TransportShardBulkAction.java:133)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.dispatchedShardOperationOnPrimary(TransportShardBulkAction.java:72)
    at org.elasticsearch.action.support.replication.TransportWriteAction$1.doRun(TransportWriteAction.java:211)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:769)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.lang.Thread.run(Thread.java:833)

```
x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/util/ShapeTestUtils.java
y[i] = lucenePolygon.getPolyY(i);
            if (hasAlts) {
                alts[i] = randomAlt();
            }
        }
        if (hasAlts) {
            return new Line(x, y, alts);
        }
        return new Line(x, y);
    }
    public static Polygon randomPolygon(boolean hasAlt) {
        XYPolygon lucenePolygon = XShapeTestUtil.nextPolygon();
        if (lucenePolygon.numHoles() > 0) {
            XYPolygon[] luceneHoles = lucenePolygon.getHoles();
            List<LinearRing> holes = new ArrayList<>();
            for (int i = 0; i < lucenePolygon.numHoles(); i++) {
                XYPolygon poly = luceneHoles[i];
                holes.add(linearRing(floatsToDoubles(poly.getPolyX()), floatsToDoubles(poly.getPolyY()), hasAlt));
            }
            return new Polygon(
                linearRing(floatsToDoubles(lucenePolygon.getPolyX()), floatsToDoubles(lucenePolygon.getPolyY()), hasAlt),
                holes
            );
        }
        return new Polygon(linearRing(floatsToDoubles(lucenePolygon.getPolyX()), floatsToDoubles(lucenePolygon.getPolyY()), hasAlt));
    }
    static double[] floatsToDoubles(float[] f) {
        double[] d = new double[f.length];
        for (int i = 0; i < f.length; i++) {
            d[i] = f[i];