title: Neo4j Cypher: Creating very large queries with UNION
body: <p>I need to query multiple paths (to draw in the UI) from different start nodes in Neo4j (could be hundreds of paths), I'm using <code>UNION</code> to combine the queries but I suspect that it's not the most efficient way to retrieve the data (I'm also using indexes on the start nodes).
  When creating large queries, all kinds of nasty stuff happen. </p>
  
  <p>The query looks something like this: </p>
  
  <pre><code>MATCH path = ((n:actor)-[*0..2]-&gt;(g)-[p:was_filmed_at]-&gt;(k:movie_set)-[l:located]-&gt;(i:state)) 
  WHERE n.name=’john doe1' AND (g:acted_in OR g:produced) 
  AND p.addDate &gt;= '2017-12-10T00:00:00+00:00' 
  AND p.addDate &lt;= '2017-12-12T08:08:06+00:00' 
  AND l.addDate &gt;= '2017-12-10T00:00:00+00:00' 
  AND l.addDate &lt;= '2017-12-12T08:08:06+00:00' 
  RETURN nodes(path), relationships(path) 
  LIMIT 1000
  
  UNION 
  
  MATCH path = ((n:actor)-[*0..2]-&gt;(g)-[p:was_filmed_at]-&gt;(k:movie_set)-[l:located]-&gt;(i:state)) 
  WHERE n.name=’john doe2' AND (g:acted_in OR g:produced) 
  AND p.addDate &gt;= '2017-12-10T00:00:00+00:00' 
  AND p.addDate &lt;= '2017-12-12T08:08:06+00:00' 
  AND l.addDate &gt;= '2017-12-10T00:00:00+00:00' 
  AND l.addDate &lt;= '2017-12-12T08:08:06+00:00' 
  RETURN nodes(path), relationships(path) 
  LIMIT 1000
  
  UNION 
  
  MATCH path = ((n:actor)-[*0..2]-&gt;(g)-[p:was_filmed_at]-&gt;(k:movie_set)-[l:located]-&gt;(i:state)) 
  WHERE n.name=’john doe3' AND (g:acted_in OR g:produced) 
  AND p.addDate &gt;= '2017-12-10T00:00:00+00:00' 
  AND p.addDate &lt;= '2017-12-12T08:08:06+00:00' 
  AND l.addDate &gt;= '2017-12-10T00:00:00+00:00' 
  AND l.addDate &lt;= '2017-12-12T08:08:06+00:00' 
  RETURN nodes(path), relationships(path) 
  LIMIT 1000
  </code></pre>
  
  <p>This is a query with only 3 paths, and it does not scale well with hundreds. Is there a simple, more efficient way to do this?</p>