Here is the general theme I want to play with:
- Vertex: "Parent" label
- Edge: "parent_to" label
- Vertex: "Child" label
I am trying to do this by doing the following:
- Create "parent" vertex and use
as("parent") - Create edge "parent_to"
- Create "child" vertex
select("parent)- Repeat edge and child vertex steps
Example:
g.addV("parent").property("parent_value","value1").as("parent")
.addE("parent_to")
.addV("child").property("child_value","value2")
.select("parent")
.addE("parent_to")
.addV("child").property("child_value","value3")
Problem is this gives me 1 parent vertex with two child vertices, but the edges loop back to and from the parent, leaving the child vertices "orphaned".
I have linked a post that gives me a working pattern, but is it really the best way to handle hierarchy in one query without need for recursion? Other QA
Note: Added a level for example's sake
g.addV("parent").as("parent")
.and(
addV("child").property("child_value","value2")
.addE("parent_to").from("parent"),
addV("child").property("child_value","value3").as("child3").and(
addV("grandchild").property("gchild_value","value4").addE("parent_to").from("child3"),
addV("grandchild").property("gchild_value","value5").addE("parent_to").from("child3")
)
.addE("parent_to").from("parent")
)
Because this will be used on AWS Neptune, I have to add everything into one query to maintain the transaction.