Suppose I have the following table in a csv
.
elementID | groupID | sequence
abc | A | 0
dcv | A | 1
asd | B | 3
ccc | B | 2
abc | B | 4
I have already created the Element
nodes in Neo4j (sequence
is not an attribute of the nodes) having as attribute the key elementID
.
From this csv
I need to create a relationship from each Element
node belonging to a group to another element belonging to the same group having the next sequence
number.
With the data above I need to create a relationship from abc
to dcv
(labeled A
for example), from asd
to abc
(labeled B
) and from ccc
to asd
labeled B
again.
I thought the query in this way:
LOAD CSV WITH HEADERS FROM "file:///file.csv" AS row
WITH row
MATCH (from:Element {elementID : row.elementID})
MATCH (to:Element {...})
MERGE (from)-[r:row.groupID]->(t)
The problem is that I do not know how to MATCH
the second node since in the graph I need the nodeID
while with the current row
variable I have only data of the from
node.
How can I do it? Is there a way to use a second variable representing another entry in the csv
to be used for the second MATCH
?
In this last case, I would need to express conditions on it such as:
WHERE row2.sequence = row.sequence+1 AND row2.groupID = row.groupID