代码之家  ›  专栏  ›  技术社区  ›  Jonas Stensved

如何在用于Elasticsearch的NEST中按_geo_distance排序?

  •  2
  • Jonas Stensved  · 技术社区  · 10 年前

    是否可以按 _geo_distance 使用NEST库进行弹性搜索?我找不到任何支持。

    做我想做的事情的原始json是:

    "sort": [
          {
             "_geo_distance": {
                "position": {
                   "lat": 59.3389428,
                   "lon": 18.0761637
                },
                "order": "asc",
                "unit": "m",
                "distance_type": "plane"
             }
          }
       ]
    
    2 回复  |  直到 10 年前
        1
  •  6
  •   bittusarkar    10 年前
    var results = client.Search<object>(sd => sd
        .SortGeoDistance(d => d
            .OnField("position")
            .Unit(GeoUnit.Miles)
            .DistanceType(GeoDistance.Plane)
            .PinTo(Lat: 59.3389428, Lon: 18.0761637)
            .Ascending());
    
        2
  •  1
  •   Sunam Debnath    6 年前
    var search2 = _client.Search < Person > (s => s
      .Sort(s => s
        .GeoDistance(g => g
          .Field("location1")
          .Order(SortOrder.Ascending)
          .DistanceType(GeoDistanceType.Plane)
          .Points(search1.Geocoord)
        )
      )
    )