2013-01-03 60 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