Reputation: 204
I am new to Neptune DB, I have created vertices and connected two vertices with edges and I have given some properties to both the edge and value
I want to retrieve both the edge and vertices properties values
Can someone provide me a sample query for this?
Thanks in advance.
Eg: Vertices: p1, P2, p3 Edges E1-connecting P1 and P2, E2- connecting P2 and P3 Vertices property: name Edge property: relation
Now I need to take out name and relation for all the vertices connected to P1
Upvotes: 2
Views: 1221
Reputation: 1419
path
step is what you are looking for. Using the by
modulator you can select properties in a round-robin fashion, i.e. vertex-edge.
Start by locating p1 vertex:
g.V().hasLabel("testV").has("name","p1")
Repeat traversal along edges with "relation" property:
.repeat(outE("testE").has("relation").inV()).until(__.not(outE("testE")))
Get the traversal path
(or tree
), and select "name" for vertices, and "relation" for edges using the by
modulator:
.path().by("name").by("relation")
To see results in arrays of strings:
.local(unfold().fold())
Note that this traversal doesn't handle cycles, but that's another question.
If you need only first level neighbors, you can take a different approach:
g.V().hasLabel("testV").has("name","p2").bothE()
.project("relation","name")
.by(values("relation"))
.by(otherV().values("name"))
Upvotes: 2