# Randomize results with the same score

**URL:** <https://discuss.elastic.co/t/randomize-results-with-the-same-score/104163>\
**Category:** Elasticsearch\
**Created:** [October 17, 2017, 3:40am UTC](https://discuss.elastic.co/t/randomize-results-with-the-same-score/104163 "2017-10-17T03:40:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kulmen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kulmen/32/12250_2.png) [@kulmen](https://discuss.elastic.co/u/kulmen)\
**Post date:** [October 17, 2017, 3:40am UTC](https://discuss.elastic.co/t/randomize-results-with-the-same-score/104163/1 "2017-10-17T03:40:10Z")

</div>

I have indexed documents with lot of not analyzed mostly numeric fields and one analyzed field 'title'. And on that data I built search engine which generates less or more complicated bool queries. In results I need to have full diversity of data so simply I need to use random order if data satisfy query. I achieved it using "function score" with "random\_score" and everything seems to be ok at least if query gives me true/false answer. But if I use in query analyzed column (title) full randomization of results is not what I want to achieve. I want to preserve an order based on the orginal score. But if, and only if there are results with the same score I need random order inside groups with the same score.

How to achieve that?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [November 10, 2017, 6:17pm UTC](https://discuss.elastic.co/t/randomize-results-with-the-same-score/104163/2 "2017-11-10T18:17:17Z")

</div>

This can be achieved by using multi sort on your search request. You want your first sort to be on \_score, and your second to be a scripted sort which returns a random value.

---

<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:** [December 8, 2017, 6:18pm UTC](https://discuss.elastic.co/t/randomize-results-with-the-same-score/104163/3 "2017-12-08T18:18:02Z")

</div>

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