Hi.
I have a catalog of products and i'm need to sort the result by price and stock. The products with stock equal 0 need to be in end of result but need to be ordered by price.
Example:
NAME -> PRICE -> STOCK
Product1 -> 150,00 -> 10
Product2 -> 140,00 -> 12
Product3 -> 135,00 -> 10
Product4 -> 160,00 -> 0
Product5 -> 150,00 -> 0
Product6 -> 140,00 -> 0
The query i'm using is this:
{
"from": 0,
"size": "12",
"query": {
"boosting": {
"positive": {
"filtered": {
"query": {
"bool": {
"must": [{
"bool": {
"should": [{"all queries here"}]
}
}]
}
},
"filter": {
"bool": {
"some": "filters"
}
}
}
},
"negative": {
"match": {
"stock_total": 0
}
},
"negative_boost": 0
}
},
"aggs": {
"some": "aggregations"
},
"sort": [
{"price_facet": {"order": "desc" } },
{"stock_total": {"order": "desc"} },
{"_score": {"order": "desc"} }
],
"track_scores": true
}