Home > Software engineering >  Elastic search order by multiple values
Elastic search order by multiple values

Time:11-24

I'm ordering my search results of elastic search by (created_at,rate,updated_at..) but it is making results irrelevance. sort query part is: [['_score' => ['order' => 'desc']],['created_at' => ['order' => 'desc']]]; Which sorts by _score and effect of created_at is really low. If i change it to [['created_at' => ['order' => 'desc']],['_score' => ['order' => 'desc']]]; the result would be totally different and are sorted by created_at and effect of _score is really low. I need something like sort with created at with weight 1 and sort with _score with weight 5 so my results are semi ordered by date and relevant.

example: My data includes title,rate,created_at like 1:['blue epic tshirt',5,'2021-11-21'] , 2:['red long epic tshirt',4,'2021-11-20'] , 3:['epic white pants',5,'2021-11-22'] , 4:['rainy weather epix',5,'2021-11-23'] and i search 'epic tshirt' so the score will be for example 5,4.5,4,1 so the result order will be 1 then 2 then 3 but when i order it with created_at after search the result order will be 4 then 3 then 2 then 1 and 4 doesn't even include 'epic tshirt'. the result which is in my mind is 3 then 2 then 1 then 4 so my results are related and ordered by created_at ( not fully ordered but created_at has an effect on them ) same thing happens when ordering with rate.

CodePudding user response:

The only solution i found is setting min_score so the results that are irrelevant to the search query will be removed, then order with the field that i like so ther will be no irrelevant result. the only problem with this solution is that if your search query is not close to your datas you wont have any result in response without min_score you would have atleast some irrelevant results if there was no relevant result.

  • Related