如何将距离值存储到 SortValues 或实体

How to Store Distance value to SortValues or Entity

如何使用 SDE4.0 @Query 和 SearchHit 将距离值存储到 SortValues 或实体

"sort": [
  {
    "_geo_distance" : {
      "codenames.geoLocation" : [
        {
          "lat" : 32.846027,
          "lon" : -96.84987
        }
      ],
      "unit" : "mi",
      "order" : "asc",
    }
  }
]

您必须在存储库查询中添加 Sort 参数,请参阅 the documentation for Spring Data Elasticsearch 4 中的描述。

在您的情况下,您需要:

Sort sort = Sort.by(
    new GeoDistanceOrder("geoLocation", new GeoPoint(32.846027, -96.84987))
        .withUnit("mi")
        .with(Sort.Direction.ASC)
);

你可以省略排序方向,因为ASC是默认值