# Get a fixed random sample from all documents

**URL:** <https://discuss.elastic.co/t/get-a-fixed-random-sample-from-all-documents/23392>\
**Category:** Elasticsearch\
**Created:** [April 24, 2015, 2:02pm UTC](https://discuss.elastic.co/t/get-a-fixed-random-sample-from-all-documents/23392 "2015-04-24T14:02:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Rickelt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebastian_rickelt/32/737_2.png) [@Sebastian\_Rickelt](https://discuss.elastic.co/u/Sebastian_Rickelt)\
**Post date:** [April 24, 2015, 2:02pm UTC](https://discuss.elastic.co/t/get-a-fixed-random-sample-from-all-documents/23392/1 "2015-04-24T14:02:46Z")

</div>

Hi,

I want to fetch a fixed large number of documents randomly from  
Elasticsearch to compute some statistics (100,000 out of 10 M documents).  
The randomness has to be predictable so that I get the same documents with  
every request.

My problem is that scan and scroll is fast but as I understand the order is  
not predictable. On the other side I could use the 'random\_score' function  
with a fixed seed in my query. That would fix the order problem but deep  
pagination is very slow. Has anyone done this before? Any ideas or pointers  
how to do this with Elasticsearch?

Any help appreciated.

Cheers,

Sebastian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e00e363a-5346-48bd-807c-4b221bed7c28%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e00e363a-5346-48bd-807c-4b221bed7c28%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 16, 2015, 11:53am UTC](https://discuss.elastic.co/t/get-a-fixed-random-sample-from-all-documents/23392/2 "2015-10-16T11:53:04Z")

</div>

Hi Sebastian,

I just stumbled on your question, did you have any luck with your random sampling yet? If your data has some criterion to filter on that is present in all documents and that divides the data into chunks that are small enough to make pagination feasible, you could combine the `random_score` with fixed seed with a filter on that criterion. Then you can repeatedly sample from the chunks and combine the results. Should be predictable as long as the data stays the same.

---

<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 5, 2017, 11:44pm UTC](https://discuss.elastic.co/t/get-a-fixed-random-sample-from-all-documents/23392/3 "2017-07-05T23:44:22Z")

</div>


