How to Store Distance value to SortValues or Entity

孤街浪徒 提交于 2020-05-17 05:44:20

问题


How to Store Distance value to SortValues or Entity using SDE4.0 @Query, and SearchHit

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

回答1:


You have to add a Sort parameter t your repository query, see the documentation for Spring Data Elasticsearch 4 where this is described.

In your case you'd need:

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

you can leave out the sort direction, because ASC is the default value



来源:https://stackoverflow.com/questions/61805654/how-to-store-distance-value-to-sortvalues-or-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!