2017-03-08 61 views
0

我有多个代表航班的geo_point字段,我希望至少在其中一个地理位置上进行过滤。ElasticSearch中多个字段上的地理过滤器

有没有一个解决方案,没有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 
      } 
      ] 
     } 
+0

你可以添加一个示例文件吗? – user3775217

+0

@ user3775217添加了一个 – aclokay

回答

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您的文档,而不是这些2英寸我会建议你为geo_point类型的位置上的每个项目设置一个nested_type,并且你可以很容易地执行nested_query,它的行为与上面的一样,只要匹配任何嵌套值就必须返回文件。

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