【问题标题】:ElasticSearch 2.x GeoPoint mapping with NEST C#ElasticSearch 2.x GeoPoint 映射与 NEST C#
【发布时间】:2016-05-05 06:53:08
【问题描述】:

我在使用 NEST C# 客户端在弹性搜索中映射“地理点”时遇到问题。

这是我的类定义:

 [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 相比)中一切都发生了巨大变化,我不知道如何正确映射地理点。有什么想法吗?

【问题讨论】:

  • 您是否在针对 ES 2.x 进行测试?
  • @Rob 是的...我确实在我的倒数第二句话中提到了这一点,但你说得对 - 我应该让它更明确..哦等等 - 它在标题中说 2.x :)
  • 哦,对了,抱歉:)
  • 但是您使用的是 NEST v2,对吗? :)
  • 也许您之前尝试了其他映射并且在应用新映射之前没有删除索引?

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


【解决方案1】:

已解决 - 将 NEST 库更新到最新版本 -

并将我的坐标类成员 Lng 重命名为 Lon:

[Number(NumberType.Double, Name = "lon")]
public double Lon { get; set; }

我认为 C# 声明并不重要,它只是重要的注释。

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-29
    • 2012-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 2019-08-27
    相关资源
    最近更新 更多