【问题标题】:NEST DBGeographyNEST DBGeography
【发布时间】:2018-08-11 08:44:16
【问题描述】:

我正在使用 Nest 6.2.0 连接到弹性搜索。

我正在尝试映射包含 DBGeography 对象的类,并尝试添加 [GeoShape] 标记,但出现以下错误。

ServerError = {ServerError: 400Type: mapper_parsing_exception 原因:“解析失败” CausedBy:“类型:not_x_content_exception 原因:“只能对某些xcontent字节或压缩的xcontent字节调用压缩器检测””}

我用来创建索引和文档的代码是:

// Create an index
response = Connection.CreateIndex(indexName, c => c
                   .Mappings(ms => ms
                   .Map<RACE.DataModels.EventModels.Event.Route>(m => m
                   .AutoMap<RACE.DataModels.EventModels.Event.Route>()
                   )
                   )
                   );

// Add document to index
result = Connection.Index(obj, i => i
                    .Index(indexName));

另外,这是我试图添加到索引中的 Route 对象的代码。

public partial class Route : BaseClass
        {
              [Key]
              public Guid ID { get; set; }

              [Required]
              [Display(Name = "Event")]
              public Guid EventID { get; set; }

              [Required]
              [Display(Name = "Route Name")]
              public string Name { get; set; }

              [Display(Name = "Description")]
              public string Description { get; set; }

              [Required]
              [Display(Name = "Path Type")]
              public int PathType { get; set; }

              [GeoShape]
              [Required]
              [Display(Name = "Route Path")]
              public DbGeography Path { get; set; }

              //[GeoShape]
              [Ignore]
              public string PathWKT { get { return Path.WellKnownValue.WellKnownText; } }

              [GeoShape]
              [Display(Name = "Start")]
              public DbGeography Start { get; set; }

              [GeoShape]
              [Display(Name = "End")]
              public DbGeography End { get; set; }

              [Display(Name = "Laps")]
              public int Laps { get; set; }

              [Display(Name = "Status")]
              public int Status { get; set; }

              [Ignore]
              [ForeignKey("EventID")]
              public virtual Event Event { get; set; }

              [Ignore]
              [ForeignKey("RouteID")]
              public virtual List<Gateway> Gateways { get; set; }

        }

DBGeography 是否会阻止对象被正确映射,我如何才能将 DBGeography 对象正确映射到 GeoShape?

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    NEST 不知道如何序列化 DbGeography 类型。您有以下选择:

    1. 编写一个 JsonConverter,可以将 DbGeography 序列化为 Elasticsearch 支持的 geo_shape geoJSON,并从 Nest.JsonNetSerializer nuget package 中序列化 hook up JsonNetSerializer 以使用此转换器。

    1. DbGeography 类型映射到NEST 知道如何序列化的相应IGeoShape 类型,并在文档POCO 上使用IGeoShape。您可能可以利用 NetTopologySuite 和 WKTReader 等类型来帮助进行转换。

    Elasticsearch 6.2.0 支持 geo_shape 输入为 WKT 但这尚未在 NEST 中公开;有an open issue to add it in the next release。至少,我希望它支持将 WKT 反序列化为 NEST 的 IGeoShape

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-02
      • 2013-04-13
      • 2016-11-09
      • 1970-01-01
      相关资源
      最近更新 更多