gpt4 book ai didi

java - elasticsearch GEO 按距离由近到远搜索顺序

转载 作者:行者123 更新时间:2023-12-02 12:49:43 33 4
gpt4 key购买 nike

映射地址属性:id name typelocation。搜索映射:

{
"address": {
"properties": {
"id": {
"type": "long"
},
"type": {
"type": "long"
},
"name": {
"type": "string"
},
"location": {
"type": "geo_point"
}
}
}
}

搜索cmd(过滤address.type = 1distance = 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的地址;我想得到按距离ASC排序的结果。怎么解决这个问题?

最佳答案

由于您是根据距离排序,因此我将匹配查询移至 boolean 过滤器内。

这应该有效

{
"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"
}
}
}

关于java - elasticsearch GEO 按距离由近到远搜索顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44646518/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com