使用 NEST C# 的 ElasticSearch 2.x GeoPoint 映射
ElasticSearch 2.x GeoPoint mapping with NEST C#
我在使用 NEST C# 客户端在 elasticsearch 中映射 "Geo Point" 时遇到问题。
这是我的 class 定义:
[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 库更新到最新版本 -
并且还将我的坐标 class 成员 Lng 重命名为 Lon:
[Number(NumberType.Double, Name = "lon")]
public double Lon { get; set; }
我认为 C# 声明并不重要,重要的只是注释。
谢谢
我在使用 NEST C# 客户端在 elasticsearch 中映射 "Geo Point" 时遇到问题。
这是我的 class 定义:
[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 库更新到最新版本 -
并且还将我的坐标 class 成员 Lng 重命名为 Lon:
[Number(NumberType.Double, Name = "lon")]
public double Lon { get; set; }
我认为 C# 声明并不重要,重要的只是注释。
谢谢