python-3.x - ElasticSearch中的地理距离排序?
问题描述
参考ES 文档,如果 lat 和 lon 都在同一个 geotype 字段中,我们可以根据地理位置进行排序。
{
"sort" : [
{
"_geo_distance" : {
"pin.location" : [-70, 40],
"order" : "asc",
"unit" : "km",
"mode" : "min",
"distance_type" : "arc",
"ignore_unmapped": true
}
}
],
"query" : {
"term" : { "user" : "kimchy" }
}
}
就我而言,我在纬度和经度的单独浮动字段中都有位置。如果我无法更改架构,如何按地理距离排序?
解决方案
您将需要使用包含地理点字段而不是两个字段(纬度、经度)的新映射创建一个新索引。然后,您需要将数据索引到新创建的索引中。查看Reindex API - 将帮助您将数据移动到新索引中。
推荐阅读
- git - 配置 git 忽略文件以排除某些 mime 类型的文件
- javascript - 从 api 调用中获取特定数据
- android - Oreo - 防止 ACTION_GET_CONTENT 使用内置文件应用程序
- django - 在 Django 模板中解析 /proc/net/route 输出
- angular - ionic firebase - TypeError: Object(...) is not a function at Firebase.getToken
- java - 无法将 java.lang.String 类型的属性值转换为所需的 java.time.LocalDateTime 类型
- html - 如何在 CSS 中创建点划线和点划线和矩形
- python - 在 python 中使用 Pandas 合并后如何查找丢弃的数据?
- reactjs - 如何启动 iframe 的 designMode?
- c# - 图像处理:如何使用锁定位执行此功能