0
votes

I am using Nest 6.2.0 to connect to elastic search.

I am trying to map a class containing DBGeography objects and I have tried adding the [GeoShape] tag and I get the following error.

ServerError = {ServerError: 400Type: mapper_parsing_exception Reason: "failed to parse" CausedBy: "Type: not_x_content_exception Reason: "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes""}

The code I am using to Create the index and document are:

// 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));

Also, here is the code for the Route object which I am trying to add to the index.

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; }

        }

Is DBGeography stopping the object from being correctly mapped, and how can I correctly map a DBGeography object to GeoShape?

1

1 Answers

0
votes

NEST doesn't know how to serialize DbGeography types. The options you have are:

  1. Write a JsonConverter that can serialize a DbGeography to geo_shape geoJSON that Elasticsearch supports, and hook up JsonNetSerializer from Nest.JsonNetSerializer nuget package to use this converter.

or

  1. Map the DbGeography type to the respective IGeoShape type that NEST knows how to serialize, and use IGeoShape on your document POCO. You could probably leverage NetTopologySuite and types such as WKTReader to help with the conversion.

Elasticsearch 6.2.0 supports geo_shape input as WKT but this is not yet exposed in NEST; there's an open issue to add it in the next release. At the very least, I expect this to support deserializing WKT to NEST's IGeoShape.