Cypher currently does not allow further processing of
UNION results, since
RETURN is required in all queries of the union. There are a couple ways around this.
Combine collections, then
UNWIND back to rows and apply
DISTINCT isn’t really needed in the above query, but it will be needed if it’s possible for a result to be present in multiple collections being combined, provided you want distinct values.
Use apoc.cypher.run() to return
UNION results from a subquery
In Neo4j 3.0.x and newer, using APOC Procedures, you can use
apoc.cypher.run() to execute a
UNION within a subquery, and return its results.
Remember that procedure calls are executed per-row, so using this approach when multiple rows already exist may lead to unintended and unexpected results.