elasticsearch - 如何将距离值存储到 SortValues 或实体
问题描述
如何使用 SDE4.0 @Query 和 SearchHit 将距离值存储到 SortValues 或实体
"sort": [
{
"_geo_distance" : {
"codenames.geoLocation" : [
{
"lat" : 32.846027,
"lon" : -96.84987
}
],
"unit" : "mi",
"order" : "asc",
}
}
]
解决方案
您必须在Sort
存储库查询中添加一个参数,请参阅Spring Data Elasticsearch 4 的文档,其中对此进行了描述。
在您的情况下,您需要:
Sort sort = Sort.by(
new GeoDistanceOrder("geoLocation", new GeoPoint(32.846027, -96.84987))
.withUnit("mi")
.with(Sort.Direction.ASC)
);
您可以省略排序方向,因为 ASC 是默认值
推荐阅读
- discord.py - 我制作了一个分配成员角色的不和谐机器人,但它不起作用
- java - 如何在Java列表中找到所有最大值?
- python - 从 Python 中不同文件中的方法访问类变量
- javascript - 使用 React 的 Django 中的动态 URL 路由
- javascript - 使用 Javascript 变量值或 url 有条件地动态生成或隐藏 html div ID
- mysql - 自动增量低于总行数
- javascript - 为什么在 ejs 中使用 fetch 后没有呈现 HTML 元素?
- android - 无法列出 com.google.android.gms:play-services-location 的版本
- javascript - 如何在静态网站的head标签中动态更改样式表和js文件的基本url
- reactjs - 类型的联合被简化为“从不”打断打字:类型被简化为“从不”,因为属性在某些成分中具有冲突的类型