0

我有以下课程

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

这段代码用于索引对象

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

如您所愿,我想索引一组位置,但由于某种原因,我在 kibana Tile 地图中看不到地理索引,当我索引 MyLocation 的平面类型时,我看到了带有地图可视化的地理索引。

在 kibana 4.0 中,我看到 Location 没有被索引 - 但无法弄清楚如何索引它......

问题出在代码上吗?kibana 中的索引?我对位置数组的索引方法?

感谢您的时间和帮助:)

4

1 回答 1

1

我在这个模型上取得了成功:

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

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

}

然后将其映射为:

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

然后它出现在 Kibana

于 2015-07-27T11:56:46.813 回答