1
votes

I try to get the shortest weighted path from Amazon Neptune graph using Gremlin, as demonstrated in TinkerPop recipes -

gremlin> g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)).
           path().as('p').
           map(unfold().coalesce(values('weight'),
                                 constant(0.0)).sum()).as('cost').
           select('cost','p')

But, I need that the output will be ordered by the calculated cost (the lowest cost as the first output) and not by the number of nodes in the path.

I tried a few combinations of order().by(..) in the query without success

1

1 Answers

1
votes

Does this give you what you need?

g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)).
           path().as('p').
           map(unfold().coalesce(values('weight'),
                                 constant(0.0)).sum()).as('cost').
           order().by(select('cost')).
           select('cost','p')