I have a controller action that allows me to search for Document
via the document GUID. The issue is that the GUIDs are 20+ characters. I would like to be able to search for the document using just say the first 5 characters of the GUID.
What I currently 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 I enter the exact GUID. But partial matching doesn't work.
您可以像这样使用WildcardQuery
search_params[:filter] = { wildcard: { "_id" => "*#{params[:document_id]}*" } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.