cypher: how to return distinct relationship types?
cypher, graph, neo4j, relationship
Solution
You might first collect all relationships on the matched path to a collection "allr", and then get the collection of distinct type(r) from the collection of all relationships,
MATCH p=(a:Philosopher)-[rel*]->(b:SchoolType)
WITH collect(rel) AS allr
RETURN Reduce(allDistR =[], rcol IN allr |
reduce(distR = allDistR, r IN rcol |
distR + CASE WHEN type(r) IN distR THEN [] ELSE type(r) END
)
)
Note, each element 'rcol' in the collection "allr" is in turn a collection of relationships on each matched path.
Problem
How to return the distinct relationship types from all paths in `cypher`? Example query: ``` MATCH p=(a:Philosopher)-[*]->(b:SchoolType) RETURN DISTINCT EXTRACT( r in RELATIONSHIPS(p)| type(r) ) as RelationshipTypes ``` This returns a collection for each path p. I would like to return a single collection contain the distinct relationship types across all collections. Here is a link to a graph gist to run the query- http://gist.neo4j.org/?7851642