solrsolrcloudsolr6

generate random numbers between two limits in solr


We have a requirement to add a random number to a field and sort it .

eg; we have rank which is integer in each document. we need to add some random number between 1-10 to rank field in each document and finally sort it in ascending.

by doing this we can rearrange the product each time we call in the solr response.


Solution

  • I was able to achieve this using the combination of sum and scale. Using the scale function i was able to scale the random_ to min and max values in my case 0 to 10.

    then use the sum function to add that value to the integer field.