ahoffer
ahoffer

Reputation: 6526

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"

Upvotes: 5

Views: 183

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41676

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

Upvotes: 4

Related Questions