Brand new to Cypher here!
I am trying to write a script that allows me to build relationship between nodes. Currently using the syntax below to make a series of nodes:
MERGE (a : Company {name:'CompanyA'}) ON CREATE SET a = {name:'CompanyA', sector:'Information Technology', lastUpdated: date()} ON MATCH SET a.lastUpdated = date()
And then attempting to establish a relationship between different nodes:
MATCH (a : Company {name:'CompanyA'})
MATCH (b : Industry {name: 'IndustryA'})
MERGE (a)-[r:BELONGS_IN]->(b) ON CREATE SET r = {revenue: '2000', lastUpdated: date()} ON MATCH SET r.lastUpdated = date()
In essence, I am trying to not create duplicate nodes (assuming both the Company and Industry nodes have already been created using the first MERGE command earlier on), instead building the BELONGS_IN relationship using these existing nodes. My problem is that I have a ton of Companies and Industries to update, and currently this syntax only allows me to run one at a time. E.g.
MATCH (a : Company {name:'CompanyA'})
MATCH (b : Industry {name: 'IndustryA'})
MERGE (a)-[r:BELONGS_IN]->(b) ON CREATE SET r = {revenue: '2000', lastUpdated: date()} ON MATCH SET r.lastUpdated = date()
MATCH (c : Company {name:'CompanyC'})
MATCH (d : Industry {name: 'IndustryC'})
MERGE (c)-[r:BELONGS_IN]->(d) ON CREATE SET r = {revenue: '2000', lastUpdated: date()} ON MATCH SET r.lastUpdated = date()
The above, for instance, wouldn't run together. I need to first run the chunk for a and b, then the chunk for c and d.
Is there a syntax that allows me to run all the code blocks in the script in one sitting? Also, if anyone has expertise on how to better format/simplify my syntax, it'd be very much appreciated! Thanks!