问题
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