Java elasticsearch按从近到远的距离排列的地理搜索顺序
映射Java elasticsearch按从近到远的距离排列的地理搜索顺序,java,elasticsearch,spring-boot,Java,elasticsearch,Spring Boot,映射地址属性:id名称类型和位置。 搜索映射: { "address": { "properties": { "id": { "type": "long" }, "type": { "type": "long" }, "name": { "type": "string" }, "location": { "type": "geo_poin
地址
属性:id
名称类型和位置
。
搜索映射:
{
"address": {
"properties": {
"id": {
"type": "long"
},
"type": {
"type": "long"
},
"name": {
"type": "string"
},
"location": {
"type": "geo_point"
}
}
}
}
搜索命令(过滤器address.type=1
和distance=100km
):
我想搜索地址匹配
type=1
和地理distance=100km
;我想得到的结果是,按距离排序ASC
。如何解决这个问题?因为您是基于距离排序的,所以我将匹配查询移动到布尔过滤器中
这应该行得通
{
"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"
}
}
}
{
"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"
}
}
}