Certain cypher queries might fail with a message similar to the below one:
Failed to create relationship ` UNNAMED1`, node `endNode` is missing.
If you prefer to simply ignore rows where a relationship node is missing, set 'cypher.lenient_create_relationship = true' in neo4j.conf
- The cypher.lenient_create_relationship flag controls the behaviour of merge/create queries where one or more of the specified nodes are missing.
- This configuration is set to false by default in all Neo4j deployments, and in such cases, further query execution fails.
- cypher.lenient_create_relationship is set to false in Aura, and we don't have an option to change this.
Solution:
- The need to set 'cypher.lenient_create_relationship = true' arises only with Cypher queries trying to create relationships with missing nodes, and such cypher queries are potentially problematic by nature.
- We recommend rewriting such queries with subqueries to allow further execution even when relation creation fails due to missing nodes.
- Consider the following example based on our sample Movie dataset:
MERGE(y:age{name:"LessThanFifty"});//Create an Age group node
MERGE(o:age{name:"MoreThanFifty"});//Create an Age group node
MATCH(m:Movie{title:'A Few Good Men'}) //Match the few Good Men Movie
WITH m
OPTIONAL MATCH (p1:Person)-[:ACTED_IN]->(m) WHERE p1.born <= 1972 // Find all actors in 'A Few Good Men', born in or before 1972
OPTIONAL MATCH (p2:Person)-[:ACTED_IN]->(m) WHERE p2.born > 1972// Find all actors in 'A Few Good Men', born after 1972
MERGE(p1)-[:OF_AGE]->(o) // create relationship between older actors and the 'MoreThanFifty' age node
MERGE(p2)-[:OF_AGE]->(y) // create relationship between younger actors and the 'LessThanFifty' age node
- This set of Cypher queries will fail with the below error message since all the actors of 'A Few Good Men' in the demo dataset were born before 1972, and there are no matches for p2.
Neo.DatabaseError.Statement.ExecutionFailed: Failed to create relationship ` UNNAMED3`, node `p2` is missing.
If you prefer to simply ignore rows where a relationship node is missing, set 'cypher.lenient_create_relationship = true' in neo4j.conf
Rewriting the Cypher query with sub-queries:
MERGE(y:age{name:"LessThanFifty"});//Create an Age group node
MERGE(o:age{name:"MoreThanFifty"});//Create an Age group node
MATCH(m:Movie{title:'A Few Good Men'}) //Match the few Good Men Movie
WITH m
MATCH (p1:Person)-[:ACTED_IN]->(m) WHERE p1.born <= 1972 // Find all actors in 'A Few Good Men', born in or before 1972
MERGE(p1)-[:OF_AGE]->(o) // create relationship between older actors and the 'MoreThanFifty' age node
WITH m
MATCH (p2:Person)-[:ACTED_IN]->(m) WHERE p2.born > 1972// Find all actors in 'A Few Good Men', born after 1972
MERGE(p2)-[:OF_AGE]->(y) // create relationship between younger actors and the 'LessThanFifty' age node
Comments
0 comments
Please sign in to leave a comment.