# How to custom sort

**URL:** <https://discuss.elastic.co/t/how-to-custom-sort/312838>\
**Category:** Elasticsearch\
**Created:** [August 24, 2022, 7:05pm UTC](https://discuss.elastic.co/t/how-to-custom-sort/312838 "2022-08-24T19:05:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guilherme\_Mello](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_mello/32/100083_2.png) [@Guilherme\_Mello](https://discuss.elastic.co/u/Guilherme_Mello)\
**Post date:** [August 24, 2022, 7:05pm UTC](https://discuss.elastic.co/t/how-to-custom-sort/312838/1 "2022-08-24T19:05:17Z")

</div>

Hello.  
I'm building a retail search.  
This search needs to give priority to products from certain stores (they pay to be more relevant).  
The roducts from these stores need to appear more frequently in the search.

I'm using script\_score to detect if the store is a "paid store". So I can give a higher score for products from this store.

The problem is that a store (with relevance payement) can have more than 100,000 products  
and the way I did, the first search pages (pagination) are only flooded with products from the store (with increased score).

Is there a way to balance these products?  
i.e. bring products from paying stores mixed with products from non-paying stores and have a more balanced results page

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 24, 2022, 10:30pm UTC](https://discuss.elastic.co/t/how-to-custom-sort/312838/2 "2022-08-24T22:30:25Z")

</div>

Welcome to our community! 😃

What about something like [Random sampler aggregation | Elasticsearch Guide [8.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.3/search-aggregations-random-sampler-aggregation.html)?

---

<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:** [September 21, 2022, 10:31pm UTC](https://discuss.elastic.co/t/how-to-custom-sort/312838/3 "2022-09-21T22:31:24Z")

</div>

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