is it possible to have aggregations with a random order? It seems that there is only asc or desc possible?
{
\"aggs\" : {
\"genders\" : {
\"terms\" :
Yes it is possible. Did it this way:
{
"aggs": {
"genders": {
"terms": {
"field": "gender",
"size": 10,
"order": {
"rnd.max": "asc"
}
},
"aggs": {
"rnd": {
"stats": {
"script": "Math.random()"
}
}
}
}
}
}
I'm using the stats-aggregation here as my random-number-generator, as it has a script-property, but any other metrics-aggregation with a script-property should do it also. You can play with the size-property of the terms-aggregation to control the number of buckets returned. The smaller the value is, the faster the aggregation runs.