简体   繁体   English

Gremlin查询以获取两个顶点之间的边

[英]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 但是低于错误org.apache.tinkerpop.gremlin.orientdb.OrientVertex无法转换为org.apache.tinkerpop.gremlin.structure.Edge

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. 因为V()返回了一个Vertex ,然后尝试使用where()进行过滤,所以使用了该错误,它将那个Vertex作为要评估的流中的传入项。 It tries to call otherV() which isn't an available method for a Vertex ...that method is meant for an edge. 它试图调用otherV() ,这不是Vertex可用的方法...该方法用于边缘。 I think that you just have the bothE() in the wrong place and therefore 我认为您只是在错误的位置放置了bothE() ,因此

g.V().hasLabel("contextlabel").
  bothE().
  where(__.otherV().hasLabel(labelName)).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM