我在使用 NEST C# 客户端在 elasticsearch 中映射“地理点”时遇到问题。
这是我的类定义:
[GeoPoint(Name = "coordinates", LatLon = true)]
public Coordinates Coordinates { get; set; }
public class Coordinates
{
[Number(NumberType.Double, Name = "lat")]
public double Lat { get; set; }
[Number(NumberType.Double, Name = "lng")]
public double Lng { get; set; }
}
我在创建索引时的映射属性:
.Mappings(map => map
.Map<Crime>(m => m.AutoMap()
.TimestampField(ts => ts.Enabled(true).Path("timeStamp"))
.Properties(pro => pro
.GeoPoint(geo => geo
.Name(n => n.Coordinates)
.LatLon(true)
))))
一旦某些文档被编入索引,我的映射看起来就不正确了....
...
"coordinates": {
"properties": {
"lat": {
"type": "double"
},
"lng": {
"type": "double"
}
}
},
...
当我尝试查询它(使用 SENSE)时,我收到以下错误:
"reason": {
"type": "query_parsing_exception",
"reason": "failed to parse [geo_bbox] query. could not find [geo_point] field [coordinates]",
"index": "someindexname",
"line": 16,
"col": 9
}
所以在我看来,问题出在我的映射上,但是在 2.x 更新(与 1.x 相比)中一切都发生了巨大变化,我不知道如何正确映射地理点。有什么想法吗?
最佳答案
已解决 - 将 NEST 库更新到最新版本 -
并且还将我的 Coordinates 类成员 Lng 重命名为 Lon:
[Number(NumberType.Double, Name = "lon")]
public double Lon { get; set; }
我认为 C# 声明并不重要,注释才是重要的。
谢谢
关于c# - 使用 NEST C# 的 ElasticSearch 2.x GeoPoint 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37044295/