【问题标题】:Elasticsearch incorrect distance calculation and filterElasticsearch不正确的距离计算和过滤
【发布时间】:2020-09-09 19:46:31
【问题描述】:

我正在对 geo_distance 过滤器使用弹性搜索,所以问题是它的距离测量与以下查询完全不同,我正在过滤 2500 米,但它返回给我一个 6500 米的地方,为什么会这样?我在谷歌地图上交叉验证点之间的距离。

查询

 
  "query": {
          "nested": {
            "path": "sellers",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "sellers.active": true
                    }
                  }
                ],
              "filter": {
        "geo_distance": {
          "distance": "226",
          "distance_type":"arc",
          "sellers.seller_geo": [ 31.0035008, 75.8480896]
        }
      }
              }
            },
            "inner_hits" : {
              
               "sort": [
          {
            "sellers.sale_price": "asc"
          }
        ],
        "size":1,
         "name": "hits_1"
            }
          }
        }
}


结果是

  "took" : 47,
  "hits" : {
    "hits" : [
      {
        "inner_hits" : {
          "hits_1" : {
            "hits" : {
              "total" : {
                "value" : 1,
                "relation" : "eq"
              },
              "max_score" : null,
              "hits" : [
                {
                  "_index" : "shopping_items",
                  "_type" : "_doc",
                  "_id" : "Z0AP8VFAEO",
                  "_nested" : {
                    "field" : "sellers",
                    "offset" : 22
                  },
                  "_score" : null,
                  "_source" : {
                    "prime" : true,
                    "instant_delivery" : true,
                    "dispatch_days" : 0,
                    "active" : true,
                    "cod" : false,
                    "discount" : "21.43",
                    "list_price" : 1964.25,
                    "seller_geo" : [
                      30.998450,
                      75.848835
                    ],
                    "postal_code" : 141001,
                    "sale_price" : 1964.25,
                    "seller_id" : "A07RE66FZA"
                  },
                  "sort" : [
                    1964.25
                  ]
                }
              ]
            }
          }
        }
      }
    ]
  }
}````

30.998450,75.848835 和 31.0035008, 75.8480896 之间的距离是 9.34km

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    [30.998450, 75.848835] 订单为lat, lon 是印度旁遮普省的一个点。反过来,它表示北极圈附近巴伦支海的一个点......

    现在,geo_distancequery,就像 geo_point 数据类型解析 lon, lat 这样的位置,从而符合 GeoJSON 标准。

    换句话说,您的地理点未正确编入索引。您可以通过删除索引并反转坐标来修复它。我个人喜欢改用以下符号

    {
      "lat":40,
      "lon":-70
    }
    

    这样人们就不会感到困惑。

    【讨论】:

    • 嘿@joe 感谢您的回答,我将很快重新索引测试并返回。
    • @NamitaSharma 运气好吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 2015-11-16
    相关资源
    最近更新 更多