弹性搜索地理距离过滤器但距离在文档上而不是在查询中

elasticserarch geo distance filter but distance is on documen instead of in the query

我有条目 "xyz" 愿意开车一定距离到一个人。

范围在文件上而不是相反

我如何构建查询来满足此要求?

谢谢

我的记录看起来很像这样

{
  "name": "XYZ",
  "pin": {
"name": "Bradford",
"location": {
  "lat": 51.5,
  "lon": 0.1
}
  },
  "max_travel_radius": "25km"
}

常规地理距离查询 会产生错误的结果,因为它与 "searcher" 与条目

的距离无关

条目有一个半径,可以通过 "searcher"

您需要创建具有 geo_shape 而不是位置的文档。您应该使用的 Geo_shape 是圆,您可以在其中指定人员位置,并指定 max_travel_distance 作为半径。请查看此 url 处的圈子。您的输入文档可能类似于

{
  "name": "XYZ",
  "pin": {
      "name": "Bradford",
     "location": {
        "type": circle, 
        "coordinates" : [101.0, 1.0],
        "radius" : "25000m"
      }
  }
}

接下来您应该使用 geo_shape query 检查一个点是否位于您上面创建的文档形状中。一个示例查询就像(您需要为嵌套查询更改它。这里只是举个例子)

GET /example/_search
{
    "query":{
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "location": {
                        "shape": {
                            "type": "point",
                            "coordinates" : [102.0, 2.0]
                        },
                        "relation": "contains"
                    }
                }
            }
        }
    }
}