Search code examples
titangremlintinkerpop3gremlin-server

Gremlin: otherV() not working inside order().by()


I'm using Tinkerpop 3.0.1 (Titan 1.0.0), and I try to list all edges for a vertex, sorted by degree of the node on the other end of the edge.

I tried:

g.V(1482896).bothE().order().by(otherV().bothE().count(), decr)

I get the following error from Titan:

The path history of the traverser does not contain a previous vertex: [e[1d2m8u-1d70ts-b2t-vs7k][82628848-DIRECTED->1482896]]

The strange thing is, there is a previous vertex in the path (namely vertex #1482896. I'm confused on how to solve this one.


Solution

  • Answering my own question, after playing around with this, I found a workaround:

    g.V(123).bothE().as('edges')
     .otherV().order().by(bothE().count(), decr)
     .select('edges')
    

    This will effectively sort edges adjacent to vertex #123 by highest degree of the node on the other end of the edge.