C# Nest:如何索引地理点数组
C# Nest: How to index array of geo-poinst
您好,我是 elastic 和 nest 的新手。
我使用了一个如何索引地理点位置的示例,效果很好,因为我可以在 kibana 地图可视化中看到地理点。
这是我的数据结构:
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; }
}
我的索引代码如下:
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}
}
});
现在我想索引 LocationArray class,似乎需要更改我的映射但我不知道该怎么做..无论如何我可以在 kibana 中看到数组数据但是无法通过地图查看。
地理点索引数组有问题吗?
好的所以经过几个小时的挖掘找到了映射这个地理点数组的方法..
希望有一天它能帮助别人 :)
client.Map<LocationArray>(m => m
.MapFromAttributes().Properties(p=>p
.NestedObject<Location>(no => no
.Name(pl => pl.Locations.First())
.Dynamic()
.Enabled()
.IncludeInAll()
.IncludeInParent()
.IncludeInRoot()
.MapFromAttributes()
.Path("full")
.Properties(pprops => pprops
.GeoPoint(ps => ps
.Name(pg => pg.Coordinate)
.IndexGeoHash().IndexLatLon()
)
)
))
);
您好,我是 elastic 和 nest 的新手。 我使用了一个如何索引地理点位置的示例,效果很好,因为我可以在 kibana 地图可视化中看到地理点。
这是我的数据结构:
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; }
}
我的索引代码如下:
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}
}
});
现在我想索引 LocationArray class,似乎需要更改我的映射但我不知道该怎么做..无论如何我可以在 kibana 中看到数组数据但是无法通过地图查看。 地理点索引数组有问题吗?
好的所以经过几个小时的挖掘找到了映射这个地理点数组的方法.. 希望有一天它能帮助别人 :)
client.Map<LocationArray>(m => m
.MapFromAttributes().Properties(p=>p
.NestedObject<Location>(no => no
.Name(pl => pl.Locations.First())
.Dynamic()
.Enabled()
.IncludeInAll()
.IncludeInParent()
.IncludeInRoot()
.MapFromAttributes()
.Path("full")
.Properties(pprops => pprops
.GeoPoint(ps => ps
.Name(pg => pg.Coordinate)
.IndexGeoHash().IndexLatLon()
)
)
))
);