# Weighted random sampling and score normalization

**URL:** <https://discuss.elastic.co/t/weighted-random-sampling-and-score-normalization/17816>\
**Category:** Elasticsearch\
**Created:** [May 29, 2014, 5:45pm UTC](https://discuss.elastic.co/t/weighted-random-sampling-and-score-normalization/17816 "2014-05-29T17:45:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dhruv\_Garg](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@Dhruv\_Garg](https://discuss.elastic.co/u/Dhruv_Garg)\
**Post date:** [May 29, 2014, 5:45pm UTC](https://discuss.elastic.co/t/weighted-random-sampling-and-score-normalization/17816/1 "2014-05-29T17:45:32Z")

</div>

Hey all,

I am using a function score to compute a score for my documents. I'd like  
to now sample from these elements at in a weighted fashion. So if my  
function\_score returns:

d1: s = 1  
d2: s = 2  
d3: s = 3

I'd like to see d3 show up as the first result 50% of the time, d2 show up  
as first result 33% of the time, and d3 show up as the first result 16% of  
the time.

Any ideas on how to implement such a scheme? I couldn't find a built in  
function to achieve this, but I may be wrong.

I think a pre-requisite to this is having the ability to normalize the  
scores that come out of my function\_score query. Any tips on how to do that  
would also be useful.

Thanks!

--  
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/a9e1b63e-4c11-4f86-a460-90879c1d844b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a9e1b63e-4c11-4f86-a460-90879c1d844b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:26am UTC](https://discuss.elastic.co/t/weighted-random-sampling-and-score-normalization/17816/2 "2017-07-06T01:26:04Z")

</div>


