Elasticsearch地理位置搜索没有返回英里单位的结果


Elasticsearch geo-location search not returning results for miles unit

我使用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
                }
            }
        }
    }
  }
}

知道为什么会这样吗?

您只需要使用正确的距离单位: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
                }
            }
        }
    }
  }
}