I want to run multiple params of search with elasticsearch-model gem like below. Before i used gem tire to search records using multiple params of queries.
My model:
class Book < ApplicationRecord
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :id, type: 'integer'
indexes :title
indexes :author
indexes :category
indexes :price
end
def self.search(params)
tire.search(load: true) do
query do
boolean do
must { string params[:title] } if params[:title].present?
must { string params[:author] } if params[:author].present?
must { string params[:category] } if params[:category].present?
should { range :price, { gte: params[:price_range_min], lte:
params[:price_range_max] } } if
params[:price_range_min].present?
&& params[:price_range_max].present?
end
end
end
end
end
My controller:
class BookController < ApplicationController
def index
@books = Book.search(params)
@books =
Kaminari.paginate_array(@books).page(params[:page]).per(10)
end
end
I followed this documentation elasticsearch-model but i am getting results only for two params of field.
Any help?