C# nest elasticsearch geo point array index not shown in kibana

1.1k views Asked by At

I have the following classes

public class MyLayer
{
    public List<MyLocation> Locations { get; set; }
}
public class MyLocation
{
    public string Name { get; set; }
    public MyCoordinate Coordinate { get; set; }
}

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

And this code to index objects

var node = new Uri("http://localhost:9200");
        string indexName = "geopoint-tests2";
        var settings = new ConnectionSettings(
            node,
            defaultIndex: "geopoint-tests2"
        );

        var client = new ElasticClient(settings);

        var rootNodeInfo = client.RootNodeInfo();
        if (!rootNodeInfo.ConnectionStatus.Success)
          throw new ApplicationException("Could not connect to Elasticsearch!",
            rootNodeInfo.ConnectionStatus.OriginalException);


        client.CreateIndex(indexName, s => s
        .AddMapping<MyLocation>(f => f
          .MapFromAttributes() 
          .Properties(p => p
            .GeoPoint(g => g.Name(n => n.Coordinate).IndexLatLon()))));

        var loc = new MyLayer()
        {
            Locations = new List<MyLocation>()
        };
        loc.Locations.AddRange(new []
                        {
                          createLocation("Amsterdam", 52.3740300, 4.8896900),
                          createLocation("Rotterdam", 51.9225000, 4.4791700),
                          createLocation("Utrecht", 52.0908300, 5.1222200),
                          createLocation("Den Haag", 52.0908300, 5.1222200)
                        });

        client.Index(loc);

As you can i want index an array of location but for some reason I can't see the geo index in kibana Tile map, when I indexed flat type of MyLocation i seen the geo index with the map visualzation.

In kibana 4.0 I see that Location is not indexed - but could not figure how to index it...

Is the problem is with code?Index in kibana?My approch of indexing array of location?

Thank you for your time and help :)

1

There are 1 answers

0
modec On

I've had success with this model:

internal class Location
{
    [JsonProperty(PropertyName = "lat")]
    public double Latitude { get; set; }

    [JsonProperty(PropertyName = "lon")]
    public double Longitude { get; set; }

}

and then mapping it with:

.MapFromAttributes()
    .Properties(p =>
        p.GeoPoint(s =>
            s.Name(n => n.Location).IndexGeoHash().IndexLatLon().GeoHashPrecision(12)
            )
        )

Then it shows up in Kibana