wuz
wuz

Reputation: 513

Neo4j Rest Transactional HTTP Endpoint Cypher: Create multiple unique Relations within one request

How do I create multiple relations within one request? The following sample request results in the following error: Neo.ClientError.Statement.InvalidSyntax","message":"WITH is required between CREATE UNIQUE and MATCH (line 1, column 281) Endpoint: Transactional Cypher HTTP endpoint http://localhost:7474/db/data/transaction/commit

Request:

{"statements":[{"statement":" 
  MATCH (nA0:Test{name:'Test B'}), (nB0:Test{name:'Test A'}) 
  CREATE UNIQUE (nA0)-[r:has_parent]->(nB0) 
  MATCH(nA1:Test{name:'Test C'}), (nB1:Test{name:'Test A'})  
  CREATE UNIQUE (nA1)-[r:has_parent]->(nB1)"}]}

It works if I submit only one MATCH ... CREATE UNIQUE Statement, is a specific delimiter required?

Thanks a lot!

Edit: Grouping the statements into a single MATCH and CREATE UNIQUE works, but a seperation of the statements would be more suitable for my pupose.

{"statements":[{"statement":" MATCH(nSrc0:Test{name:'Test B'}),(nTrgt0:Test{name:'Test A'}),(nSrc1:Test{name:'Test C'}),(nTrgt1:Test{name:'Test A'})  CREATE UNIQUE (nSrc0)-[r0:has_parent]->(nTrgt0), (nSrc1)-[r1:has_parent]->(nTrgt1)"}]}

Upvotes: 0

Views: 361

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41676

As the error says you have to add a WITH between a CREATE UNIQUE and the next MATCH to separate writing from reading clauses.

  1. put the two statements in two separate entries in the request
  2. use parameters
  3. use MERGE instead of CREATE UNIQUE

see:

{"statements":[

{"statement":
 "MATCH (a:Test{name:{name_a}}), (b:Test{name:{name_b}}) MERGE (a)-[:has_parent]->(b)",
 "parameters":{"name_a":"Test B","name_b":"Test A"}},

{"statement":
 "MATCH (a:Test{name:{name_a}}), (b:Test{name:{name_b}}) MERGE (a)-[:has_parent]->(b)",
 "parameters":{"name_a":"Test C","name_b":"Test A"}},
...
]}

Upvotes: 2

Related Questions