无法将地理图形插入到弹性搜索中

本文关键字:搜索 插入 图形 | 更新日期: 2023-09-27 18:24:11

我正试图将数据从sql转移到弹性搜索。每次尝试添加多边形时,我都会遇到一个例外。

我使用WktReader阅读WKT,并将其添加到JeoJson类中。该类包含类型(多边形)和坐标

坐标构建(c#):

{ [ [ [ x,y ], [ x,y ], [ x,y ], [ x,y ], [ x,y ] ] ] }

弹性搜索中的几何映射:

"GEOMETRIES" : {
    "type" : "nested",
    "properties" : {
        "AREA" : { "type" : "double" },
        "CENTROID" : {
            "type" : "geo_point",
            "geohash" : true,
            "geohash_preflix" : true
        },
        "KEY" : {
            "type" : "string",
            "index" : "not_analyzed"
        },
        "SHAPE" : {
            "type" : "geo_shape"
        }
    }
}

有两个例外:

1

MapperParsingException[failed to parse [GEOMETRIES.SHAPE]]; nested: IllegalArgumentException[Invalid number of points in LinearRing (found 3 - must be 0 or >= 4)];

2

MapperParsingException[failed to parse [GEOMETRIES.SHAPE]]; nested: InvalidShapeException[provided shape has duplicate consecutive coordinates at: (number, number, NaN)];

无法将地理图形插入到弹性搜索中

我解决了它。

IllegalArgumentException是因为多边形的第一个和最后一个坐标是质心,只有第二个和最后前一个才是真正的第一个点和最后一点。我所做的只是删除第一点和最后一点。

InvalidShapeException是因为一些多边形基本上是一条线,弹性搜索不喜欢

最后,两个错误都是因为我得到的多边形都搞砸了