title: Create atmost one relationship for newly created node with existing node based on some property
body: <p>My application receive stream of data which I need to persist in graph DB. With this data , I am first creating nodes in neo4j db in batches (of 1000) and just after that I am trying to find out matching node in existing data to link it.</p>
  
  <pre><code>MATCH(new:EVENT) where new.uniqueId in [NEWLY CREATED NODES UNIQUE ID]
  MATCH (existing:EVENT)  where new.myprop = existing.myprop and new.uniqueId &lt;&gt; exising.uniqueID
  CREATE (new)-[:LINKED]-(existing)
  </code></pre>
  
  <p>My problem is, if for a node there are more than one matching existing node than i want to create relationship with just one existing node. My current above  query will create relationship with all matching nodes.</p>
  
  <p>is there any efficient way of doing it as number of existing node could be huge ie approx 300M.</p>
  
  <p>Node: I have index created on myprop and uniqueId field</p>