Elasticsearch 地理位置搜索不返回英里单位的结果
Elasticsearch geo-location search not returning results for miles unit
我正在使用 elasticsearch return 用户位置附近的业务。
如果我使用公里的距离单位进行搜索 'km' 我会得到预期的结果,但是如果我使用英里 'm' 它 return 0 次点击
具有命中的 km 请求示例
{
"sort" : [
{
"_geo_distance" : {
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
},
"order" : "asc",
"unit" : "km"
}
}
],
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "1km",
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
}
}
}
}
}
}
1km = 0.6 英里所以这个查询应该 return 与上面相同数量的结果但是 returns 0
{
"sort" : [
{
"_geo_distance" : {
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
},
"order" : "asc",
"unit" : "m"
}
}
],
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "1m",
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
}
}
}
}
}
}
知道为什么会这样吗?
您只需使用 correct distance unit:m
用于米,对于英里您需要使用 mi
{
"sort" : [
{
"_geo_distance" : {
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
},
"order" : "asc",
"unit" : "mi" <--- here
}
}
],
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "1mi", <--- here
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
}
}
}
}
}
}
我正在使用 elasticsearch return 用户位置附近的业务。
如果我使用公里的距离单位进行搜索 'km' 我会得到预期的结果,但是如果我使用英里 'm' 它 return 0 次点击
具有命中的 km 请求示例
{
"sort" : [
{
"_geo_distance" : {
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
},
"order" : "asc",
"unit" : "km"
}
}
],
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "1km",
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
}
}
}
}
}
}
1km = 0.6 英里所以这个查询应该 return 与上面相同数量的结果但是 returns 0
{
"sort" : [
{
"_geo_distance" : {
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
},
"order" : "asc",
"unit" : "m"
}
}
],
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "1m",
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
}
}
}
}
}
}
知道为什么会这样吗?
您只需使用 correct distance unit:m
用于米,对于英里您需要使用 mi
{
"sort" : [
{
"_geo_distance" : {
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
},
"order" : "asc",
"unit" : "mi" <--- here
}
}
],
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "1mi", <--- here
"location" : {
"lon": -0.11454850000000001,
"lat": 51.4911665
}
}
}
}
}
}