如何使用elasticsearch应用过滤器

时间:2015-08-18 09:48:39

标签: elasticsearch

我正面临着使用'轮胎'宝石。我已对文章应用搜索并希望应用过滤器,以便在搜索中不显示草稿文章。我的代码如下:

search_controller.rb

def articles_search
   @articles = Article.search(params)
end

article.rb

include Tire::Model::Search
include Tire::Model::Callbacks

  def self.search(params)
    if params[:query].present?
      tire.search(load: true) do
        query { string params[:query]} 
        filter :terms, :state => ['published']
      end
    else
      tire.search(load: true) do
        query { string "*#{params["term"]}*"}
        filter :terms, :state => ['published'] 
      end
    end 
  end

在文章表中有一个列状态我只想要那些状态为'已发布的文章。但它不起作用。如果我使用filter,它会给出一个空结果:terms,:state => ['发表&#39]。

0 个答案:

没有答案
相关问题