Search code examples
elasticsearchmappingnest

How to create mapping for geopoint properties using fluent api and attributes in Nest?


I am trying to configure mapping for geopoint property using Nest v5.5.0

I have this model(type) Address which has this property:

 [GeoPoint(Name = "coordinates")]
 public Coordinates Coordinates { get; set; }

The Coordinates class:

    public class Coordinates
{
    [Number(NumberType.Float, Name = "lat")]
    public float Lat { get; set; }

    [Number(NumberType.Float, Name = "lng")]
    public float Lng { get; set; }
}

and using the fluent api:

.Mappings(m => m
      .Map<AdvertiserType>(map => map
                 .AutoMap()
                 .Properties(p => p
                      .GeoPoint(geo => geo
                             .Name(n => n.Coordinates)
                                )
                            )
                      )
     )

But When I try to index data I got parse exception.Could please tell me how to map geopoints properties using Nest5.5.0?


Solution

  • Use NEST's GeoLocation type which will be mapped as a geo_point using automapping