Find distinct values of predicates and sort them

Let say I have a data sample as below:

“set”: [
{
“name”:“A”,
“dgraph.type”: “node” ,
“rating” :5
},
{
“name”:“A”,
“dgraph.type”: “node” ,
“rating” :2
},
{
“name”:“B”,
“dgraph.type”: “node” ,
“rating” :5
},
{
“name”:“B”,
“dgraph.type”: “node” ,
“rating” :1
}]

I want to find the distinct values of rating present in the data set and “sort in desc order”.

The query I tried:
query=“”"
{
find(func:type(node)) @groupby(rating)
{
count(uid)
}
}“”"

Output I got :{ {5,count:2}, {1, count:1}, {2,count:1} }

Output I expect :{ {5,count:2}, {2, count:1}, {1,count:1} } [I want all distinct values of rating and sort them in the query itself. Currently, I am adding the output I am getting in an array and hen sorting it to get desired results]

If you wanna use groupBy. You should convert “rating” :1 to a node. For example

{
  "name": "A",
  "dgraph.type": "node" ,
  "rating" : {
     "name": "rating 5",
     "dgraph.type": "Rating" ,
     "rating": 5
     }
}

This way you can use groupby correctly.

What could be alternative of groupby?
If I want to find distinct values for a particular predicate and sort it in descending order?

Queue the response, you could do it in a lambda or on client side. :face_with_peeking_eye: