2013-01-03 54 views
2

我爲每個帳戶都有一個單獨的索引,其中每個模型(用戶和註釋 - 僅僅是一個示例,實際應用程序有很多模型)的映射都已指定。elasticsearch中帶有獨立過濾器的多類型搜索

include Tire::Model::Search 

Tire.index('account_1') do 
    create(
    :mappings => { 
     :user => { 
     :properties => { 
      :name => { :type => :string, :boost => 10 }, 
      :company_name => { :type => :string, :boost => 5 }, 
      :blocked => { :type => :boolean, :include_in_all => false } 
     } 
     }, 
     :comments => { 
     :properties => { 
      :description => { :type => :string, :boost => 5 } 
     } 
     } 
    } 
) 
end 

如何在我的搜索查詢中添加過濾器,以便在搜索結果中僅返回阻止=> true的用戶。 這不應該影響評論類型的搜索結果。 這可能嗎? elasticsearch中是否有過濾器可以做同樣的事情?

回答

1

得到的答案...

可以使用的一個或組合未存在和長期濾波器...

search_key = 'test' 
    Tire.search [account_1] do 
     query do 
     filtered do 
      query { string search_key } 
      filter :or, { :not => { :exists => { :field => :blocked } } }, 
         { :term => { :blocked => true } } 
     end 
     end 
    end