Hello, I have an issue and I hope you can help me.
I have imported some csv-Files to create nodes and it worked. They include just generic simple data.
For example:
Now I want to create multiple relationships with just one query. Of course I can do it like that ...
but I want something like an loop, that works incremently depend on the ID`s.
For example (pid=1) on (aid=10) (pid=2) on (aid=11) and so on.
Is there an opportunity to do that just with cypher-code or any tools ?
unwind [1,2,3,4,5,6,7,8,9,10] as loop
match (p1:Person {pid: loop}), (a1:Address {aid:10+loop})
create (p1)-[:LIVING_IN]->(a1);
though in the above the first pass would evaluate to {pid: 1} and {aid: 11} , the 2nd would be {pid: 2} and {aid: 12} and isnt exactly what you want so maybe {aid: 10+loop} should be {aid:9+loop} so as to get {pid: 1} and {aid: 10} and the 2nd pass of {pid: 2} and {aid: 11} etc. Simply an example
regarding the syntax error my mistake. you need one final trailing ')' at the end of the line and thus as well as my mistake again in that you can not do a create within a foreach. However you can merge and presumably accomplish the same as originally requested and
foreach ( loop in range (1,200) | merge (p1:Person {pid: loop})-[:LIVING_IN]->(a1:Address {aid:10+loop}) )
and so the above will find a
:Person node at pid=loop
:Address node at aid:10+loop
if they dont exist, create said nodes and then also create a relationship between said nodes. If the :Person and :Address nodes already/previously exist then we will not create additional nodes, and the same for the relationship as well
Note, that I have node-key-constraints on pid & aid ...
When I drop them and do the query with merge I will get new nodes AND relations.
Thats not what I am looking for.