如何在NEST中为Elasticsearch按_geo_distance排序?

问题描述 投票:2回答:2

是否可以通过带有弹性搜索的NEST库按_geo_distance进行排序?我找不到任何支持。

做我想做的原始json是:

"sort": [
      {
         "_geo_distance": {
            "position": {
               "lat": 59.3389428,
               "lon": 18.0761637
            },
            "order": "asc",
            "unit": "m",
            "distance_type": "plane"
         }
      }
   ]
elasticsearch nest
2个回答
4
投票
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());

0
投票
var search2 = _client.Search < Person > (s => s
  .Sort(s => s
    .GeoDistance(g => g
      .Field("location1")
      .Order(SortOrder.Ascending)
      .DistanceType(GeoDistanceType.Plane)
      .Points(search1.Geocoord)
    )
  )
)
© www.soinside.com 2019 - 2024. All rights reserved.