Gopi Gopi - 2 months ago 7
Scala Question

Fetch outgoing edge property value between two vertices in scala gremlin

I am trying to fetch edge property value between two vertices. E.g. A-->B
A 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.

Answer

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.