I am currently using gremlin with aws neptune cluster and using nodejs for development. I have find friends with same interest and order by mutual interest count. I need to limit results to top 2.
const res = await g.V().has('user', 'name', 'Waruna').as('u')
.out('like').in_('like')
.where(P.neq('u'))
.valueMap()
.by(gremlin.process.statics.unfold())
.groupCount()
.order(gremlin.process.scope.local)
.by(gremlin.process.column.values, gremlin.process.order.desc)
.limit(2)
.toList();
console.log('RESULTS', res);
Results:
RESULTS [
Map {
Map { 'name' => 'Dimuthu', 'age' => 30 } => 2,
Map { 'name' => 'Kamal', 'age' => 25 } => 1,
Map { 'name' => 'Amal', 'age' => 34 } => 1,
Map { 'name' => 'Dhanushka', 'age' => 40 } => 1,
Map { 'name' => 'Sunimal', 'age' => 28 } => 1
}
]
Though I limit query to 2 it is not working. It resulted all nodes.
After the groupCount
step you have essentially created a single map structure. So the limit(2)
does nothing as that map is considered one entity. If you add an unfold()
before the limit(2)
you should get just two results. Bear in mind if the map created by groupCount
has the potential to become large you may want to consider ways to filter the results sooner. As an alternative you can give the limit
step local scope using limit(local,2)
.