elasticsearch - 如何搜索多个 geo_distance 查询
问题描述
我想使用 geo_distance 查询(使用 ES 7.3)搜索多个位置。例如:
在柏林搜索 +10km
搜索慕尼黑 +10km
并给我一个综合结果。
基本上我在这里试过这个:
一个阵列geo_distance
不起作用。很想在这方面得到一些帮助:)
解决方案
搜索多个位置映射的简单示例:
PUT location
{
"mappings": {
"properties" : {
"pin" : {
"type" : "geo_point"
}
}
}
}
数据:
[
{
"_index" : "location",
"_type" : "_doc",
"_id" : "rhn8f20BIb7c4jbYhr3Z",
"_score" : 1.0,
"_source" : {
"pin" : {
"lat" : 40.73,
"lon" : -74.1
}
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "rxn8f20BIb7c4jbYz709",
"_score" : 1.0,
"_source" : {
"pin" : {
"lat" : 40.717,
"lon" : -73.99
}
}
}
]
询问:
GET location/_search
{
"query": {
"bool": {
"should": [ ---> multiple filters in should clause , either one of these has to be true
{
"geo_distance" : {
"distance" : "1km",
"pin" : {
"lat" : 40.73,
"lon" : -74.1
}
}
},
{
"geo_distance" : {
"distance" : "1km",
"pin" : {
"lat" : 40.717,
"lon" : -73.99
}
}
}
]
}
}
}
推荐阅读
- css - VueJS - 在显示元素之前旋转
- amazon-web-services - 认知 OAuth2 流程
- android - 回收站视图中没有数据
- c++ - 是否存在经过认证的(ISO 26262 或类似的)C++ 标准库?
- r - 函数如何读取其包内的静态 csv 文件
- terraform - Terraform 中交互变量的加载顺序
- sql - 如何执行从 Spring JDBC 到 PostgreSQL 的带有多个分号的单个 SQL 查询?
- javascript - Javascript ID 转换为 onchange 变量
- yii2 - 如何获取有关用户在 Yii2 中进入哪个控制器的时间的指标
- android - 如何检查 android 签名 apk 特定案例的崩溃日志