# Can I sort results by price and take sold out product to last of results?

**URL:** <https://discuss.elastic.co/t/can-i-sort-results-by-price-and-take-sold-out-product-to-last-of-results/125568>\
**Category:** Elasticsearch\
**Created:** [March 26, 2018, 9:12am UTC](https://discuss.elastic.co/t/can-i-sort-results-by-price-and-take-sold-out-product-to-last-of-results/125568 "2018-03-26T09:12:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nutanek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nutanek1/32/29009_2.png) [@nutanek1](https://discuss.elastic.co/u/nutanek1)\
**Post date:** [March 26, 2018, 9:12am UTC](https://discuss.elastic.co/t/can-i-sort-results-by-price-and-take-sold-out-product-to-last-of-results/125568/1 "2018-03-26T09:12:35Z")

</div>

I have a problem that is I want to sort product by **price (desc)** and want **sold out product** shows at **the last of results** like below.

```
{
    "price": 1000
    "inventory": 2
}
{
    "price": 500
    "inventory": 10
}
{
    "price": 200
    "inventory": 1
}
{
    "price": 30
    "inventory": 5
}
{
    "price": 1500
    "inventory": 0
}
{
    "price": 900
    "inventory": 0
}

```

I try to use multi-fields sorting, but it's not working.

If I want to do like this, what should I do?

Thanks for your helps^^

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2018, 12:53pm UTC](https://discuss.elastic.co/t/can-i-sort-results-by-price-and-take-sold-out-product-to-last-of-results/125568/2 "2018-03-26T12:53:27Z")

</div>

I wonder if `function_score` would help you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 23, 2018, 12:54pm UTC](https://discuss.elastic.co/t/can-i-sort-results-by-price-and-take-sold-out-product-to-last-of-results/125568/3 "2018-04-23T12:54:00Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
