如何在NEST中按_geo_distance对Elasticsearch进行排序?

时间:2016-02-08 15:55:46

标签: elasticsearch nest

是否可以按_geo_distance对NEST库进行弹性搜索排序?我无法找到任何支持。

做我想要的原始json是:

"sort": [
      {
         "_geo_distance": {
            "position": {
               "lat": 59.3389428,
               "lon": 18.0761637
            },
            "order": "asc",
            "unit": "m",
            "distance_type": "plane"
         }
      }
   ]

2 个答案:

答案 0 :(得分: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());

答案 1 :(得分: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)
    )
  )
)