Hi, I've been trying to understand how to perform field collapsing returning results in random sort order using 2.1.1.
My use case: I want to return a list of documents that match specific restrictions that I specify, field collapsed by a field called supplierId. I want the specific document returned for each supplierId returned in repeatable random order.
When I run the following query (in-lining scripts because I'm still learning how to run queries on my workstation, this isn't a production environment), it behaves in the manner that I'm expecting:
"script": "(new Random()).nextInt()",
Each time I submit this request, a different document is returned, along with a different value of "sort."
If I try to add a seed to Random() by sending something like "script": "(new Random(0)).nextInt()" with everything else being exactly the same, the top result returned is always the same and the sort value is always -1155484576. This seems to make sense, because I want repeatable randomness based on the seed. However, changing the seed from 0 to 1 returns the same part that was returned with a seed of 0, though the sort value is now -1155869325. Any time I specify a seed value into the constructor of Random(), no matter what the value, the same part is returned (though the sort value does change depending on what seed value I enter).
I'm not sure why this works when I don't specify a seed value, but seems to break the moment I enter a seed value, and I was wondering if someone could please let me know if I'm doing something wrong. Thank you in advance!