Sort Elasticsearch results by integer value via Searchkick
Solution 1:
Because Elasticsearch stores IDs as strings rather than integers, I solved this problem by adding a new obj_id
field in ES and ordering results based on that.
In my Post and Project models:
def search_data
{
:obj_id => id,
:title => title,
:content => ActionController::Base.helpers.strip_tags(content),
}
end
And in the controller I changed the order
value to:
:order => { :obj_id => :desc }
The records are sorting correctly now.