# Random sort order

**URL:** <https://discuss.elastic.co/t/random-sort-order/3766>\
**Category:** Elasticsearch\
**Created:** [January 11, 2011, 8:16pm UTC](https://discuss.elastic.co/t/random-sort-order/3766 "2011-01-11T20:16:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [January 11, 2011, 8:16pm UTC](https://discuss.elastic.co/t/random-sort-order/3766/1 "2011-01-11T20:16:01Z")

</div>

I'm interested in pulling ten results from my query, but I want the results  
to be random. Is there anything built in, or would I create a custom scoring  
function that just returns a random number?

-- jim

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 11, 2011, 8:18pm UTC](https://discuss.elastic.co/t/random-sort-order/3766/2 "2011-01-11T20:18:31Z")

</div>

Custom scoring function is the best way, with a random seed passed as a parameter.  
On Tuesday, January 11, 2011 at 10:16 PM, James Cook wrote:

> I'm interested in pulling ten results from my query, but I want the results to be random. Is there anything built in, or would I create a custom scoring function that just returns a random number?
> 
> -- jim

---

<div class="post-metadata">

**Author:** ![Ben\_Roubicek](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@Ben\_Roubicek](https://discuss.elastic.co/u/Ben_Roubicek)\
**Post date:** [April 6, 2011, 3:59am UTC](https://discuss.elastic.co/t/random-sort-order/3766/3 "2011-04-06T03:59:49Z")

</div>

I am a little new to ES, but I am also looking to do the same thing. For a "custom scoring function", does that mean something that is installed on the cluster, or does mean a custom script that is passed in to the cluster?

Could you give an example as to how the random sort order could be done using the Java API?

---

<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:** [July 6, 2017, 4:08am UTC](https://discuss.elastic.co/t/random-sort-order/3766/4 "2017-07-06T04:08:52Z")

</div>


