当您尝试在 ES 中按距离排序时,结果通常包含匹配项与您的搜索位置之间的距离:
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "circle",
"_type": "doc",
"_id": "7",
"_score": null,
"_source": {
"id": 7,
"coordinates": {
"lon": 112.548443,
"lat": 37.780269
}
},
"sort": [
116.39283058047849
]
},
{
"_index": "circle",
"_type": "doc",
"_id": "5",
"_score": null,
"_source": {
"id": 5,
"coordinates": {
"lon": 112.55061,
"lat": 37.779145
}
},
"sort": [
231.9203763747634
]
}
]
} 排序距离包含在sort
字段中。如何使用 elasticsearchTemplate 在 Spring Date Elasticsearch 2.1.16 中获得排序距离?
这是我的查询代码: Page<CircleES> resultPage = elasticsearchTemplate.queryForPage(searchQuery, CircleES.class);