Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade to neo4j 2.1 broke Cypher query

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"
like image 329
ahoffer Avatar asked Oct 01 '22 14:10

ahoffer


1 Answers

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
like image 101
Michael Hunger Avatar answered Oct 28 '22 17:10

Michael Hunger