# Random sort with a seed changes after updating a doc

**URL:** <https://discuss.elastic.co/t/random-sort-with-a-seed-changes-after-updating-a-doc/15711>\
**Category:** Elasticsearch\
**Created:** [February 11, 2014, 12:00am UTC](https://discuss.elastic.co/t/random-sort-with-a-seed-changes-after-updating-a-doc/15711 "2014-02-11T00:00:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Williams](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_williams/32/1811_2.png) [@Brandon\_Williams](https://discuss.elastic.co/u/Brandon_Williams)\
**Post date:** [February 11, 2014, 12:00am UTC](https://discuss.elastic.co/t/random-sort-with-a-seed-changes-after-updating-a-doc/15711/1 "2014-02-11T00:00:57Z")

</div>

I'm using random\_score to perform a search with some random sorting,  
something as simple as this:

{  
"fields": [  
"id"  
],  
"query": {  
"function\_score": {  
"random\_score": {  
"seed": 773372  
}  
}  
},  
"sort": [  
{  
"\_score": "desc"  
}  
]  
}

As soon as I update a doc in the index its position will change with this  
sort. I took a diff of the before and after result set, and with a set of  
about 180 documents I noticed 8 documents switched places after the update.

If I insert a doc instead of updating a doc then it works as expected. The  
new doc is inserted into a random spot, but in a consistent manner.

Is this the expected behavior?

--  
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/91c6877b-fd70-4bbd-bad2-7fe0ab9643c6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/91c6877b-fd70-4bbd-bad2-7fe0ab9643c6%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Arny\_2](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@Arny\_2](https://discuss.elastic.co/u/Arny_2)\
**Post date:** [July 17, 2014, 2:36pm UTC](https://discuss.elastic.co/t/random-sort-with-a-seed-changes-after-updating-a-doc/15711/2 "2014-07-17T14:36:51Z")

</div>

I'm facing the same issue.  
Is there no way to choose what the seed actually should pick for the random  
score calculation?  
Or just let it pick the uid which never changes.

On Tuesday, February 11, 2014 1:00:57 AM UTC+1, Brandon Williams wrote:

> I'm using random\_score to perform a search with some random sorting,  
> something as simple as this:
> 
> {  
> "fields": [  
> "id"  
> ],  
> "query": {  
> "function\_score": {  
> "random\_score": {  
> "seed": 773372  
> }  
> }  
> },  
> "sort": [  
> {  
> "\_score": "desc"  
> }  
> ]  
> }
> 
> As soon as I update a doc in the index its position will change with this  
> sort. I took a diff of the before and after result set, and with a set of  
> about 180 documents I noticed 8 documents switched places after the update.
> 
> If I insert a doc instead of updating a doc then it works as expected. The  
> new doc is inserted into a random spot, but in a consistent manner.
> 
> Is this the expected behavior?

--  
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/428e6570-93ca-4d46-940c-450dc4841b69%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/428e6570-93ca-4d46-940c-450dc4841b69%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:15am UTC](https://discuss.elastic.co/t/random-sort-with-a-seed-changes-after-updating-a-doc/15711/3 "2017-07-06T01:15:11Z")

</div>


