2012-12-17 43 views
0

我正在爲我的數據庫使用Mongoid/MongoDB和Tire/ElasticSearch。我想根據_id的數組篩選我的結果。下面是一些僞代碼類似於我嘗試:由Mongo過濾ElasticSearch結果_id

search = Tire::Search::Search.new() 
search.filter :terms, :_id => [array_of_ids] 

當我換出:_id屬性,並嘗試使用其他索引的屬性,它工作正常。但是,:_id不會返回任何結果。

回答

0

原來你不能過濾:_id:id。無論這是特定輪胎還是ElasticSearch,我都不確定。

在我的Tire自定義映射中,我已經提前添加了一個重複字段作爲一種別名。更多僞代碼:

tire.mapping do 
    indexes :id,   :index => :not_analyzed 
    indexes :content_id, :analyzer => :keyword, 
         :as  => "_id" 
    ... 
end 

重要的部分是indexes :content_id, :as => "_id"。從那時起,我使用:content_id進行過濾。

+0

請嘗試http://www.elasticsearch.org/guide/reference/query-dsl/ids-filter.html過濾器。 – karmi