Just use groupCount
:
gremlin> g = new TinkerGraph()
==>tinkergraph[vertices:0 edges:0]
gremlin> user1 = g.addVertex('u1')
==>v[u1]
gremlin> user2 = g.addVertex('u2')
==>v[u2]
gremlin> product1 = g.addVertex('p1')
==>v[p1]
gremlin> product2 = g.addVertex('p2')
==>v[p2]
gremlin> product3 = g.addVertex('p3')
==>v[p3]
gremlin> user1.addEdge('like',product1)
==>e[0][u1-like->p1]
gremlin> user1.addEdge('like',product2)
==>e[1][u1-like->p2]
gremlin> user2.addEdge('like',product2)
==>e[2][u2-like->p2]
gremlin> user2.addEdge('like',product3)
==>e[3][u2-like->p3]
gremlin> g.v('u1','u2').out('like').groupCount().sort{-it.value}
Cannot invoke method negative() on null object
Display stack trace? [yN] n
gremlin> g.v('u1','u2').out('like').groupCount().cap.next().sort{-it.value}
==>v[p2]=2
==>v[p1]=1
==>v[p3]=1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…