简体   繁体   中英

Fetch outgoing edge property value between two vertices in scala gremlin

I am trying to fetch edge property value between two vertices. Eg A-->BA and B are two vertices and it has edge with property(name).

My code looks like:

graph.V().hasLabel(A).outE().value("name").headOption()

It gives me the property value for name.

In a given two vertices, i am getting None as output

graph.traversal().V().hasLabel(A).outE("test").outV().hasLabel(B).properties("name").headOption()

' test ' - Edge Label ' name ' - Edge property

Any idea what is wrong with my query.

Apologies for not being able to answer this in your comments on the previous question you asked. I think what you are looking for is:

graph.traversal().V()
     .hasLabel("A").outE("test").as("x").otherV()
     .hasLabel("B").select("x").properties("name");

If you just want the values of the properties on the edge you can do the following:

graph.traversal().V()
     .hasLabel("A").outE("test").as("x").otherV()
     .hasLabel("B").select("x").values("name");

Side Note (Why is your original traversal wrong): Your original traversal:

graph.traversal().V().hasLabel(A).outE("test").outV().hasLabel(B).properties("name").headOption()

is doing the following:

  1. Get all vertices with the label "A"

  2. From those vertices follow the outward going edges which have the label "test" to vertices which have the label "B"

  3. Then get the property "name" from those vertices

You are actually asking for the properties on the vertex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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