c# - 使用 NEST C# 的 ElasticSearch 2.x GeoPoint 映射

标签 c# elasticsearch nest elasticsearch-net elasticsearch-2.0

我在使用 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/

相关文章:

elasticsearch - 从ElasticSearch中的嵌套字段中删除对象

vb.net - ElasticSearch分析的字段

elasticsearch - 嵌套查询在 bool 中写入必须和应该

c# - 余弦相似度代码(非项向量)

elasticsearch - elasticsearch:索引和搜索阿拉伯文本

hadoop - Rhadoop 与 Elasticsearch-hadoop

.net - 使用NEST在Elasticsearch中检索未知数量的文档

c# - FakeItEasy 的 Out 和 Ref 参数

c# - 在 .NET 中从混淆中排除构造函数

c# - 找出图像之间的差异