title: replace nodes (and rels) with cypher
body: <p>I have a large database with 700K properties. But some are duplicate so I now want to "clean" all this stuff...</p>
  
  <p>I'm looking forward to replace 1+ node(s) by 1+ other(s) and to link all relationships that could exist for this node. </p>
  
  <p>So I would like to do something like : </p>
  
  <pre><code>MATCH (p:Property) WHERE p.uid IN ['A6271DFB-F0FD-0DF1-6F22-67F7D3164AE6']
  WITH p AS sources
  MATCH (p2:Property) WHERE p2.uid IN ['51A26A14-74FB-BCFC-FE5C-661A43A9377C','8DCD063C-965D-CC12-6159-E287CD000954']
  WITH sources, p2 AS destinations
  OPTIONAL MATCH (sources)-[k]-&gt;(n) MERGE (destinations)-[y]-&gt;(n) SET y=k
  WITH sources, destinations
  OPTIONAL MATCH (sources)&lt;-[s]-(n) MERGE (destinations)&lt;-[w]-(n) SET w=s
  WITH sources
  DETACH DELETE sources
  </code></pre>
  
  <p>Off course, it doesn't work because I need to specify the relationship type for the merge... but I actually don't know it (because it could be several types and depending the type, the rel could have properties)...</p>
  
  <p>So right now, I developed a PHP-script to MATCH all nodes+rels; and FOREACH record; generate a MERGE query to link them to the new node... But that's slow and not optimized... </p>
  
  <p>Does anyone have a clue on this ?</p>