【问题标题】:Multi type search with independent filters in elasticsearchelasticsearch中具有独立过滤器的多类型搜索
【发布时间】:2013-01-03 11:24:16
【问题描述】:

我对每个帐户都有一个单独的索引,其中指定了每个模型(用户和 cmets - 只是一个示例,实际应用程序有很多模型)的映射。

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 的用户。 这应该不会影响 cmets 类型的搜索结果。 这可能吗? elasticsearch中是否有任何过滤器可以做同样的事情?

【问题讨论】:

    标签: elasticsearch ruby-on-rails-2 tire


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2017-06-17
      • 1970-01-01
      • 2014-09-08
      • 2011-09-28
      • 1970-01-01
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多