elasticsearch - Elasticsearch - 过滤 geo_distance 查询
问题描述
我有一个包含两个字段的映射类型:位置(geo_point)和类型(短)。
我想按地理位置列出我的地点并使用这种查询
{
"query": {
"bool": {
"filter": {
"geo_distance": {
"distance": "20km",
"location": {
"lat": 48.856614,
"lon": 2.3522219
}
}
}
}
},
"aggs": {
"types": {
"terms": {
"field": "type"
}
}
},
"post_filter": [],
"page": 1,
"size": 50,
"sort": [
{
"_geo_distance": {
"location": {
"lat": 48.856614,
"lon": 2.3522219
},
"order": "asc",
"unit": "km",
"distance_type": "plane"
}
}
]
}
有没有办法只包含特殊类型的前 2 个位置(例如 type=2)?
解决方案
向过滤器添加另一个子句,例如
{
"query": {
"bool": {
"filter": [{
"geo_distance": {
"distance": "20km",
"location": {
"lat": 48.856614,
"lon": 2.3522219
}
}
},
{
"term": {"type":"2"}
}]
}
},
"aggs": {
"types": {
"terms": {
"field": "type"
}
}
},
"post_filter": [],
"page": 1,
"size": 2,
"sort": [
{
"_geo_distance": {
"location": {
"lat": 48.856614,
"lon": 2.3522219
},
"order": "asc",
"unit": "km",
"distance_type": "plane"
}
}
]
}
推荐阅读
- reactjs - mxCodec 无法正确解码 xml
- python - 如何对具有多个类标签的数据进行编码?
- batch-file - 如何使用批处理文件移动文件?
- python - 列表的最大值(每个索引的长度可能不同)和一个数字
- excel - 从表单创建多个 PDF 文件
- sql - 您如何在 SQL 中表示“辅助键”
- python - 子组 pandas 中值的计数频率
- reactjs - 为什么文件字段为空?React 文件上传到 .net core web api
- python - 使用 Python 调试器时如何指定模块(-m)?
- php - 使用参考代码 [xxx],PayU Laravel 无法处理订单