I have a bunch of Cypher statements I'm tryring to execute using Neo4J browser to create relationships between nodes:
MATCH a, b WHERE a.name = 'X' AND b.name = 'Y' CREATE (a)-[:KNOWS]->(b)
WITH 1 as dummy
MATCH a, b WHERE a.name = 'X' AND b.name = 'Z' CREATE (a)-[:KNOWS]->(b)
(I added WITH 1 as dummy as a workaround as suggested here)
The problem is if a node doesn't match in the first query the second match doesn't work even though both nodes exist in that query. When I change the order of the above statements, the second statement creates a relationship.
When I run the first one it doesn't throw an error, it just shows "(no changes, no rows)" in the query results. But somehow it interrupts the execution of the rest.
Is there any way to let it ignore if it a node doesn't exist and move to the next statement?
Also I'd appreciate if you can recommend a better/easier way of creating these relationships in Cypher (I'll investigate import tool later).
Thanks.
UPDATE: I guess the problem was just about the Neo4J browser. I tried running the same commands in a cql file from Neo4Jshell and it worked just fine. Just needed some modification as below:
MATCH a, b WHERE a.name = 'X' AND b.name = 'Y' CREATE (a)-[:KNOWS]->(b);
MATCH a, b WHERE a.name = 'X' AND b.name = 'Z' CREATE (a)-[:KNOWS]->(b);
Otherwise it gives a warning
Warning: Exiting with unterminated multi-line input.
I guess after all it's much better this way as copy/paste to browser is not suitable for large amounts of data anyway. And now I can get rid of the "WITH 1 as dummy" workaround.