【问题标题】:Apply geo distance filter on nested field在嵌套字段上应用地理距离过滤器
【发布时间】:2014-07-14 18:15:37
【问题描述】:

我的映射包含这样的嵌套字段:

"Locations": {
  "type": "nested",
  "properties": {
    "Name": {
      "type": "string"
    },
    "GeoPoint": {
      "type": "geo_point"
    }
  }
}

所以基本上我要做的是在文档的每个位置存储一些附加属性。

不幸的是,这似乎不适用于geo distance filter:

GET /myIndex/myType/_search
{
  "filter": {
    "geo_distance": {
      "distance": "100 mi",
      "Locations.GeoPoint": {
        lat: 40.70,
        lon: -74.00
      }
    }
  }
}

不会返回任何结果,而如果 GeoPoint 直接位于文档本身而不是嵌套字段上,则过滤器可以正常工作:

GET /myIndex/myType/_search
{
  "filter": {
    "geo_distance": {
      "distance": "100 mi",
      "GeoPoint": {
        lat: 40.70,
        lon: -74.00
      }
    }
  }
}

有没有办法让地理距离过滤器与嵌套字段上的 geo_point 一起工作?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    nested filter 完成这项工作:

    GET /myIndex/myType/_search
    {
      "filter" : {
        "nested" : {
          "path" : "Locations",
          "filter" : {
            "geo_distance": {
              "distance": "100 mi",
              "GeoPoint": {
                "lat": 40.70,
                "lon": -74.00
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      对于 ElasticSearch 5.5 用户的更新,@Max 的答案已被弃用,因为嵌套过滤器和嵌套查询功能使用点表示法,而不是在查询周围显式包装“嵌套”字段。

      例如:

      {
          "query": {
              "nested" : {
                  "path" : "obj1",
                  "score_mode" : "avg",
                  "query" : {
                      "bool" : {
                          "must" : [
                          { "match" : {"obj1.name" : "blue"} },
                          { "range" : {"obj1.count" : {"gt" : 5}} }
                          ]
                      }
                  }
              }
          }
      }
      

      更多信息:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-05
        • 1970-01-01
        • 1970-01-01
        • 2013-04-13
        • 1970-01-01
        • 1970-01-01
        • 2021-02-16
        • 2011-03-12
        相关资源
        最近更新 更多