Skip to content

Instantly share code, notes, and snippets.

@xeraa
Created September 21, 2016 01:49
Show Gist options
  • Save xeraa/d06f834b2ec098583de1a5ef9110712a to your computer and use it in GitHub Desktop.
Save xeraa/d06f834b2ec098583de1a5ef9110712a to your computer and use it in GitHub Desktop.
GET /raffle/_search
{
"size": 1,
"query": {
"function_score": {
"functions": [
{
"random_score": { }
}
],
"score_mode": "sum"
}
}
}
@dadoonet
Copy link

In 6.4.0, make sure to run a forcemerge to have only one segment when you have few documents.
Example:

DELETE raffle
PUT raffle
{
  "settings": {
    "number_of_shards": 1
  }
}
POST raffle/_doc
{
  "name": "User 1"
}
POST raffle/_doc
{
  "name": "User 2"
}
POST raffle/_doc
{
  "name": "User 3"
}
POST raffle/_forcemerge?max_num_segments=1
GET /raffle/_search
{
  "query": {
    "function_score": {
      "functions": [
        {
          "random_score": { }
        }
      ],
      "score_mode": "sum"
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment