How to fuzzy match a ruby on rails elasticsearch. -
i have controller action allows me search document
via document guid. issue guids 20+ characters. able search document using first 5 characters of guid.
what have is:
search_params = { sort: { sent_at: :desc } } if can_search && params[:document_id].present? search_params[:filter] = { term: { "_id" => params[:document_id] } } @documents = elasticsearch::model.search(search_params, [document]) else @documents = elasticsearch::model.search(search_params, [document]).page(params[:page]).per(20) end
this works fine if enter exact guid. partial matching doesn't work.
you can using wildcardquery that
search_params[:filter] = { wildcard: { "_id" => "*#{params[:document_id]}*" } }
Comments
Post a Comment