samedi 27 juin 2015

C# Nest: How to index array of geo-poinst

Hello I am new to elastic and nest. I used a example of how to index geo point location that worked fine as I can see the geo-points in kibana map visualize.

This is my data structure:

public class LocationArray
{
    public string ArrayNameArtical { get; set; }
    [ElasticProperty(Type = FieldType.GeoPoint)]
    public IEnumerable<Location> Locations { get; set; }
}
public class Location
{
    public string Name { get; set; }

    [ElasticProperty(Type = FieldType.GeoPoint)]
    public Coordinate Coordinate { get; set; }
}


public class Coordinate
{
    public double Lat { get; set; }
    public double Lon { get; set; }
}

And my code to index as follow:

var response = client.CreateIndex(indexName, s => s
      .AddMapping<Location>(f => f
        .MapFromAttributes() 
        .Properties(p => p
          .GeoPoint(g => g.Name(n => n.Coordinate).IndexGeoHash().IndexLatLon())
        )
      )
    );
    client.IndexMany(new[]{
        new Location
        {
            Name = "Amsterdam",
            Coordinate = new Coordinate { Lat =  52.3740300, Lon = 4.8896900}
        },
        new Location
        {
            Name = "Rotterdam",
            Coordinate = new Coordinate { Lat = 51.9225000, Lon = 4.4791700}
        },
        new Location
        {
            Name = "Utrecht",
            Coordinate = new Coordinate { Lat =  52.0908300,  Lon = 5.1222200}
        },new Location
        {
            Name = "Den Haag",
            Coordinate = new Coordinate { Lat =  52.3740300, Lon = 4.8896900}
        }
    });

Now i want to index the LocationArray class, it seems that in need to change my mapping but i colund't figure out how to do it..anyway i can see the array data in kibana but cant view it over map. Is there any problem with indexing array of geo-point?

Aucun commentaire:

Enregistrer un commentaire