我正在使用elasticsearch在用户位置附近返回商家。
如果我以距离单位公里的距离搜索' km'我得到了预期的结果,但如果我使用里程数' m'它返回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英里所以此查询应返回与上述相同数量的结果,但返回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
}
}
}
}
}
}
为什么会出现这种情况?
答案 0 :(得分:1)
您只需使用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
}
}
}
}
}
}