【问题标题】:Setting up location with type in NEST Elastic Search使用 NEST Elastic Search 中的类型设置位置
【发布时间】:2017-01-13 23:32:11
【问题描述】:

我有以下弹性索引项:

{
        "_index": "areas",
        "_type": "area",
        "_id": "AVb_MPXHCPQmPhMEnjGo",
        "_score": 1,
        "_source": {
          "name": "Chorlton somewhere",
          "location": {
            "type": "Point",
            "coordinates": [
              -2.2852634,
              53.4417472
            ]
          }
        }
      }

现在在 NEST 中,我的班级看起来像:

[String]
public string Name { get; set; }

[GeoPoint]
public GeoLocation Location{ get; set; }

我希望能够在 C# 中使用类型和坐标来表示位置。

我知道这是错误的,但是我不知道如何在C#的类结构中实现上述JSON的结构

【问题讨论】:

  • 您应该尝试GeoShape 而不是GeoLocation,因为您的location 点不是geo_point,而是geo_shape
  • @Val 如果我将属性的属性设置为 GeoShape,在这种情况下我需要为属性使用什么类型?
  • 在你的情况下,PointGeoShape 我猜
  • 啊,我在寻找 Geo... 一开始。看起来很有效!
  • 酷,很高兴它正在工作!

标签: elasticsearch nest


【解决方案1】:

根据您的 JSON,您有一个 geo_shape 而不是 geo_point,因此您的 Location 字段声明应该如下所示

[GeoShape]
public PointGeoShape Location{ get; set; }

【讨论】:

    猜你喜欢
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 2019-11-04
    • 1970-01-01
    • 2013-07-23
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多