2016-12-07 65 views
0

在elasticsearch中,我想用geo_distance过滤器查询多个索引。多索引上的Elasticsearch geo_distance过滤器

问题是一个索引具有geo_point映射,另一个没有geo_point映射。

如果我使用纬度和经度查询,我只会得到具有geo_point映射的索引的结果。对于其他索引我得到未能找到geo_point字段异常。

如何从两个索引中获得结果?

以下是我的查询。

{ 
"query":{ 
    "filtered":{ 
     "query":{ 
      "bool":{ 
       "should":{ 
        "match_all":{ 

        } 
       } 
      } 
     }, 
     "filter":{ 
      "bool":{ 
       "should":[ 
        { 
         "bool":{ 
          "must":[ 
           { 
            "geo_distance":{ 
             "distance":"50km", 
             "location":{ 
              "lat":22.5705741, 
              "lon":88.4355427 
             } 
            } 
           } 
          ] 
         } 
        } 
       ] 
      } 
     } 
    } 
}, 
"sort":[ 
    { 
     "_geo_distance":{ 
      "location":{ 
       "lat":22.5705741, 
       "lon":88.4355427 
      }, 
      "order":"asc", 
      "unit":"km" 
     } 
    } 
], 
"size":30, 
"from":0 
} 

我使用elasticsearch优化版本0.90.12

+0

很明显嘛,如果你的第二个指标没有geo_point场,使用geo_distance过滤器查询它会很困难,不是吗?你可以尝试的一件事是使用['type' filter](https://www.elastic.co/guide/en/elasticsearch/reference/0.90/query-dsl-type-filter.html)并结合' geo_distance'过滤器中的'type'类型具有geo_point。但是,如果geo_distance是唯一的过滤器,我看不到从没有任何geo-ish信息的另一个索引检索结果的要点。 – Val

+0

@Val还有一个匹配查询以及geo_distance过滤器。我会尝试一下类型过滤器,并让你知道它是怎么回事。 – tungri

+0

@Val你可以给一个在解释场景中使用类型过滤器的例子吗?即对一个索引具有geo_point字段且在另一个索引中丢失的索引进行geo_distance搜索。谢谢 – tungri

回答

0

请参阅您最后的评论,我认为你可以试试这个:

{ 
"query": { 
    "filtered": { 
    "filter": { 
     "bool": { 
      "should": [ 
       { 
       "bool": { 
        "must": [ 
         { 
          "term": { 
          "_index": "index_name_with_geo_point" 
          }, 
          "geo_distance": { 
          "from": 100, 
          "to": 200, 
          "distance_unit": "km", 
          "location": { 
           "lat": 40.73, 
           "lon": -74.1 
          } 
          } 
         } 
        ] 
       } 
       }, 
       { 
       "term": { 
        "_index": "Index_name_without_geo_point" 
       } 
       } 
      ] 
     } 
    } 
    } 
} 
} 
现在

  • 的ducument必须从具有地理位置和地理位置范围的索引
  • t他的文件不是来自具有地理位置的索引。

当然啦,你可以展开的第二个元素应查询到bool : {must : {terms : {}}}为第一个是 ,但做到这一点,只有当它是必要

相关问题