Upgrade to neo4j 2.1, triggered a Cypher request

A newer version of Cypher no longer likes my OPTIONAL MATCH clause. What is the correct version of this query for Cypher 2.1?

Cannot add labels or properties on a node which is already bound (line 1, column 104)
"MATCH (n1:Entity {key:"bloomberg michael"})-[r1:RELATED_TO]-(n2:Entity) 
 WITH n1, r1, n2 
 OPTIONAL MATCH (n2:Entity)-[r2:RELATED_TO]-(n3:Entity) 
 RETURN n1, r1, n2, count(n3), labels(n1), labels(n2) 
 ORDER BY n2.relevance DESC  
 LIMIT 50"
+4
source share
1 answer

Can you try

MATCH (n1:Entity {key:"bloomberg michael"})-[r1:RELATED_TO]-(n2:Entity) 
 WITH n1, r1, n2 
 OPTIONAL MATCH (n2)-[r2:RELATED_TO]-(n3:Entity) 
 RETURN n1, r1, n2, count(n3), labels(n1), labels(n2) 
 ORDER BY n2.relevance DESC  
 LIMIT 50
+4
source

Source: https://habr.com/ru/post/1544410/


All Articles