简体   繁体   中英

How to sort with elasticsearch?

I am trying to make methods for sorting desc and asc . I am using rails, tire gem and elasticsearch. I am trying to figure out what sort params I can send in the URL

So I have defined in the search-block that it is sorting the result desc order.

sort { by :price, "desc"}

When a user search for apartments in: new-york the result is sort desc order.

The search query/URL looks like this:

http://localhost:3000/apartmens?utf8&query=newyork

Why cant I add a sort-params in the url, like this:

http://localhost:3000/apartmens?utf8&query=newyork&sort=asc

I believe it would be something like this.

params[:sort] ||= 'asc'
Tire.search('apartmens') do |s| 
   s.query do |q|
     q.string 'newyork'
   end
   s.sort { by :__FIELD_YOU_WANT_TO_SORT_, params[:sort]}
end

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM