對於輪胎(ElasticSearch包裝寶石),如何查詢和篩選具有某個屬性的nil/null值的索引記錄。舉例來說,如果我有這樣的關係輪胎(彈性搜索)無比較
class Article < ActiveRecord::Base
belongs_to :topic
end
我的文章索引,但我希望避免與topic_id =零拉回記錄。我試過這個代碼打擊,但沒有奏效。
class Article
belongs_to :topic
def search(q)
tire.search do
...
filter :missing, :field => :topic_id, { :existence => false, :null_value => false }
...
### filter :range, :topic_id => { :gt => 0 } # ==> I tried this as well but didn't work
...
end
end
end
對不起,但這是用於輪胎寶石DSL(ElasticSearch包裝)。不是ActiveRecord。 – RubyFanatic