【问题标题】:Elasticsearch geo-location search not returning results for miles unitElasticsearch地理位置搜索不返回英里单位的结果
【发布时间】:2017-03-01 03:35:11
【问题描述】:

我使用弹性搜索返回用户位置附近的业务。

如果我使用公里“km”的距离单位进行搜索,我会得到预期的结果,但如果我使用英里“m”,它会返回 0 次点击

带有命中的公里请求示例

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

任何想法为什么会这样?

【问题讨论】:

标签: php search elasticsearch geolocation location-services


【解决方案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
                }
            }
        }
    }
  }
}

【讨论】:

    猜你喜欢
    • 2013-03-15
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多