gpt4 book ai didi

c# - 如何在Elastic Search中为带有GeoShape字符串GeoJson多边形的类型化对象编制索引?

转载 作者:行者123 更新时间:2023-12-02 23:34:34 24 4
gpt4 key购买 nike

我有一个类型化的类,其中包含代表多边形的GeoJson字符串变量。
如何使用NEST在Elastic Search中为其编制索引?
用以下方式标记字段:

[ElasticProperty(Type = FieldType.GeoShape)]
public string Polygon { get; set; }

并在 CreateIndex中将其作为
 .GeoShape(s => s
.Name(m => m.Polygon)
.Tree(GeoTree.Geohash)
.TreeLevels(2)
.DistanceErrorPercentage(0.025))

给出此错误:

failed to parse [polygon]]; nested: ElasticsearchParseException[Shape must be an object consisting of type and coordinates"



由于我将GeJSon作为输入,而GeoShape的坐标则为Geo JSON,如何映射此数据?我可以反序列化输入并填充ES结构,但这似乎太复杂了,容易出错。

谢谢,

莫妮卡

最佳答案

我写了a blog post about working with Geospatial queries with Elasticsearch and NEST

处理要持久保存为geo_shape类型并在应用程序中轻松使用它们的字段的一种好方法是使用NetTopologySuite,它包含一个串行器,用于在其中转换IGeometry类型(例如Polygon,LineString,MultiPolygon)。代码导入GeoJSON,即geo_shape类型支持的格式。然后可以将序列化器注册到NEST客户端,以便正确处理IGeometry类型的模型属性。

I have an example of doing this up on BitBucket.

关于c# - 如何在Elastic Search中为带有GeoShape字符串GeoJson多边形的类型化对象编制索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32831085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com