title: Neo4j - Cypher: merge duplicate relationships
body: <p>I have duplicate relationships between nodes e.g:</p>
  
  <pre><code>A -&gt;{weight: 1} B
  A -&gt;{weight: 1} B
  A -&gt;{weight: 1} B
  </code></pre>
  
  <p>and I want to merge these relations into one relation of the form: A->{weight: 3} B for my whole graph. </p>
  
  <p>I tried something like the following:</p>
  
  <pre><code>start n = node(*) 
  match (n)-[r:OCCURENCE]-&gt;()
  Set r.weight = count(*)
  count(*)
  </code></pre>
  
  <p>But my graph is really big and with this query edges are updated twice for each node A and B. Furthermore the old relationships are not deleted. Don't know how to model these two aspects in one query. Hope someone can help.</p>
  
  <p>EDIT:</p>
  
  <p>Tried some other querys with node(<em>) and relationship(</em>) e.g </p>
  
  <pre><code>start n = node(*) match ()-[r:OCCURENCE]-&gt;() set n.SumEdgeWeight = sum(r.weight)
  </code></pre>
  
  <p>They are processing horrible slow. Is there any other faster way when I need to update all nodes? I found this topic [1] in the Neo4j community. Is it possible that my querys run with the java core api faster?</p>
  
  <p>[1] <a href="https://groups.google.com/forum/#!topic/neo4j/4SSxvNsuQsY" rel="nofollow">https://groups.google.com/forum/#!topic/neo4j/4SSxvNsuQsY</a></p>
  
  <p>Regards. </p>