I use Elasticsearch in my Rails application (elasticsearch-model, elasticsearch-rails gems). I wrote a simple search:
def search
@posts = params[:term] ? Post.search(params[:term]) : []
render json: @posts
end
It works good. But I made some fixes in order to do search among 'deleted=false' and 'enabled=true' subset then :
def search
@posts = params[:term] ? Post.existing.enabled.search(params[:term]) : []
render json: @posts
end
Post
class Post < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
scope :existing, ->{ where(deleted: false) }
scope :enabled, ->{ where(enabled: true) }
end
Post.import
It doesn't work - I see the same results as in the previous case(with any value in 'deleted' and 'existing' columns. How can I fix it? Thanks in advance.