2016-12-07 60 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 : {}}}爲第一個是 ,但做到這一點,只有當它是必要

相關問題