I have a Piece model with a boolean attribute of published.
I want the search results to only contain Pieces that are plublished: true.
My index action for the PiecesController is:
def index
@list = params[:list]
@sort = params[:sort]
if params[:q]
@pieces = Piece.search(params[:q]).records
else
@pieces = Piece.all_in_category(@list, @sort)
end
end
From searching around it seems that I should overwrite the search method in the Piece controller but I am not sure the correct way of doing this to maintain the current search methods functionality.
What is the best way to filter the elasticsearch results using the elasticsearch-rails gem?
Piecework? eg.scope :published, -> {where(published: true)}and then callingPiece.published.search(params[:q]).records? I have limited experience with elastic but it is very well documented so I would start there.params[:q]looks like. Or checkoutelastic-scopesas it seems to modify AR scope to fit nicely withelasticsearch