一个映射address属性:id、name、type和location。搜索映射:
{
"address": {
"properties": {
"id": {
"type": "long"
},
"type": {
"type": "long"
},
"name": {
"type": "string"
},
"location": {
"type": "geo_point"
}
}
}
}搜索命令(过滤address.type = 1和distance = 100km):
XGET /_search
{
"query": {
"filtered": {
"query": {
"match": {
"type": 1
}
},
"filter": {
"geo_distance": {
"distance": "100km",
"location": {
"lat": 24.46667,
"lon": 118.1
}
}
}
}
}
}我想搜索匹配type = 1和地理位置distance = 100km;的地址,并且想要得到order by distance ASC的结果。如何解决这个问题?
发布于 2017-06-20 16:57:51
由于您是基于距离进行排序的,因此我将匹配查询移到了布尔过滤器中。
这应该是可行的
{
"query": {
"bool": {
"must": [{
"geo_distance": {
"distance": "1000000km",
"location": {
"lat": 24.46667,
"lon": 118.1
}
}
},
{
"term": {
"type": {
"value": 1
}
}
}
]
}
},
"sort": {
"_geo_distance": {
"location": "24.46667,118.1",
"order": "asc"
}
}
}https://stackoverflow.com/questions/44646518
复制相似问题