Reputation: 953
Is it possible to return in a single cypher query distinct nodes and edges of a specific path. For instance, using the movies graph the query below return separately movies and actors, I'd like to return all nodes together. using path p = (...) and nodes(p) actually returns pairs of nodes regardless the use of distinct.
match (m:Movie {name: "Rain"}) -- (p:Person) return {nodes: collect(distinct {name: m.title}), actors: collect(distinct {name: a.name}), links: collect({source: m.title, target: a.name})}
Thanks in advance for any help, Pierre
Upvotes: 2
Views: 2081
Reputation: 953
Got some help internally, so I'm sharing the answer. With neo'j 2.1.5, one can use unwind. The query following query returns in once the list of distinct nodes and distinct edges in the path - at least it worked with my examples:
match path = (p:Person {Name: 'Rain'})-[]-(m:Movie) unwind nodes(path) as p unwind rels(path) as r
return {nodes: collect(distinct p), links: collect(DISTINCT {source: id(startNode(r)), target: id(endNode(r))})}
Upvotes: 2