# Random score, but keep X random values from a field on top

**URL:** <https://discuss.elastic.co/t/random-score-but-keep-x-random-values-from-a-field-on-top/169463>\
**Category:** Elasticsearch\
**Created:** [February 21, 2019, 4:39pm UTC](https://discuss.elastic.co/t/random-score-but-keep-x-random-values-from-a-field-on-top/169463 "2019-02-21T16:39:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Destroy666](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@Destroy666](https://discuss.elastic.co/u/Destroy666)\
**Post date:** [February 21, 2019, 4:39pm UTC](https://discuss.elastic.co/t/random-score-but-keep-x-random-values-from-a-field-on-top/169463/1 "2019-02-21T16:39:23Z")

</div>

I'm wondering if that's possible with some sort of custom function query - have the results random, but keep results with X values (one time each) from one field at the top, so that we have at least one result from each category present. They also should be random.

---

<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:** [March 21, 2019, 4:39pm UTC](https://discuss.elastic.co/t/random-score-but-keep-x-random-values-from-a-field-on-top/169463/2 "2019-03-21T16:39:30Z")

</div>

Closed on March 21, 2019, 4:39pm UTC

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