# ES sort in server end when given fileds are equal

**URL:** <https://discuss.elastic.co/t/es-sort-in-server-end-when-given-fileds-are-equal/294517>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [January 17, 2022, 2:10am UTC](https://discuss.elastic.co/t/es-sort-in-server-end-when-given-fileds-are-equal/294517 "2022-01-17T02:10:37Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [January 17, 2022, 4:15am UTC](https://discuss.elastic.co/t/es-sort-in-server-end-when-given-fileds-are-equal/294517/4 "2022-01-17T04:15:13Z")

</div>

[`random_score` for function score query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-random) is enough for you? It returns random score based on internal Lucene doc ids as a source of randomness, which is renumbered by merges.

If you want differente results even for repeated same query, maybe you have to use some script field with painless.

> [@Random function in Painless?](https://discuss.elastic.co/t/random-function-in-painless/70280):
>
> Hello, What is the way to genereate a random value in Painless? Being able to draw one value from a set would be particularly great - I want to use it to add a new field to my mock data and I need a possibility to add one of the statuses ('Working', 'Archived', 'InReview') to my documents at random.

---

_[View the full topic](https://discuss.elastic.co/t/es-sort-in-server-end-when-given-fileds-are-equal/294517)._
