ElasticSearch中多个字段的地理过滤器

时间:2017-03-08 10:15:19

标签: elasticsearch geo

我有多个表示航班的geo_point字段,我想在地理位置上至少对其中一个点进行过滤。

是否存在没有 bool或子句的解决方案?

索引映射:

    "Flight":{
                "properties":{
                    ...
                    "point_src":{"type":"geo_point"},
                    "point_dest":{"type":"geo_point"},
                    ...
                }
            }

示例文件:

{
          "point_dest": [
            {
              "lat": 50.110922,
              "lon": 8.682127
            }
          ],
          "point_src": [
            {
              "lat": 33.893791,
              "lon": 35.501777
            }
          ]
      }

1 个答案:

答案 0 :(得分:0)

之所以要求您提供excat文档,是为了找出您可以匹配的geo_points数量。我看起来目前你只有两个geo_points,所以你可以做以下查询。 Geo_distance查询和应该布尔

{
    "query": {
        "bool": {
            "should": [{
                "bool": {
                    "filter": {
                        "geo_distance" : {
                    "distance" : "20000000km",
                    "point_src" : {
                        "lat" : 40,
                        "lon" : -70
                    }
                }
                    }
                }
            },
            {
                "bool": {
                    "filter": {
                        "geo_distance" : {
                    "distance" : "200km",
                    "point_dest" : {
                        "lat" : 40,
                        "lon" : -70
                    }
                }
                    }
                }
            }]
        }
    }
}

注意 - 再次,如果您的文档中有多个geo_points而不是这两个。我建议你为geo_point类型的位置中的每个项目的位置设置一个nested_type,你可以很容易地执行与上面相同的nested_query,只需从任何嵌套值中匹配一个必须退回文件。

{
    "settings": {
        "analysis": {}
    },
    "mappings": {
        "product": {
            "dynamic": "strict",
            "properties": {
                "locations": {
                    "type": "nested",
                    "properties": {
                        "point": {
                            "type": "geo_point"
                        }
                    }
                }
            }
        }
    }
}
相关问题