I want to get all distinct node names in that graph. But I want to filter on a property of C. How can I filter on a property of C without leaving out nodes D? Something similar to the following query:
MATCH (root:Root {key: 'abcde'})
MATCH p=(root)-[:r1|r2|r3|r4*..3]-(n:A|B|D|C {property: 'abc'})
UNWIND nodes(p) AS node
RETURN DISTINCT node.key AS name
ORDER BY name ASC
Additionally, how can I get all the distinct triples instead of the node names?
since D is connected to A this looks as an easy problem. You can do the following query that you have written yourself, by using the QPP: Concepts - Cypher Manual.
If you can write show how your graph looks and what you expect as a result, I could help you with a query that would solve the issues.
MATCH (root:Root {key: 'abcde'})
MATCH p=(root)-[:r1|r2|r3|r4*..3]-(n:A|B|D|C)
WHERE not n:C or (n:C and n.property = 'abc')
UNWIND nodes(p) AS node
RETURN DISTINCT node.key AS name
ORDER BY name ASC