【问题标题】:C# Nest: How to index array of geo-poinstC# Nest:如何索引地理点数组
【发布时间】:2015-06-28 03:22:23
【问题描述】:

您好,我是弹性和嵌套的新手。 我使用了一个示例来说明如何索引地理点位置,因为我可以看到 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 类,似乎需要更改我的映射但我不知道该怎么做..无论如何我可以在 kibana 中看到数组数据,但无法在地图上查看它。 地理点的索引数组有问题吗?

【问题讨论】:

    标签: c# arrays elasticsearch nest


    【解决方案1】:

    好的,经过几个小时的挖掘,找到了映射这个地理点数组的方法。 希望有一天它会帮助别人:)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多