Q: Gremlin query to get the edge between two vertices Trying something like this 
List<Edge> result = g.traversal().V().hasLabel("contextlabel").where(__.otherV().hasLabel(labelName)).bothE().toList();

But getting below error 
org.apache.tinkerpop.gremlin.orientdb.OrientVertex cannot be cast to org.apache.tinkerpop.gremlin.structure.Edge

A: You're getting that error because V() returns an Vertex and then you try to filter with where() which takes that Vertex as the incoming item in the stream to evaluate. It tries to call otherV() which isn't an available method for a Vertex...that method is meant for an edge. I think that you just have the bothE() in the wrong place and therefore 
g.V().hasLabel("contextlabel").
  bothE().
  where(__.otherV().hasLabel(labelName)).

