0
votes

I'm using elasticsearch 7.7 and I have product documents which are like following :

[
     {"id": 1, "title": "product 1", "status": "available"},
     {"id": 2, "title": "product 2", "status": "will_be_available_soon"},
     {"id": 3, "title": "product 3", "status": "not_available"},
     {"id": 4, "title": "product 4", "status": "never_will_be_available_again"},
]

In my search queries I want to sort my products in a way that first I see available products, then I want to see will_be_available_soon products and after that not_available and of course at last never_will_be_available_again. and for products with the same status I want to sort based on their matching score.

1
Is that ok for you to do that with scoring? - Gibbs
@Gibbs Yes, it is. but It would be great if I had both options :D - mhndev
is that ok for you to change the mapping? scripting is quicker way to achieve but it is not good at performance. - Gibbs

1 Answers

0
votes

You can run a custom query script. Have a look on this discussion: https://discuss.elastic.co/t/sorting-or-ordering-by-specific-values/67244/2 Another option is the score but might be an issue in a future.