Forgive me if this is not the correct place to ask a question about cypher queries. I'm extremely new to neo4j and am curious if anyone has solved this problem before.
I've got a graph of parent/child relationships which form a tree of Person nodes. Each Person node has a property Name. Given a known list of Names, I need to test for the existence of a path where each string in the List represents a node in the path. Here's a conceptual hierarchy:
[Arthur]→[Bob]→[Charlie]→[Dave]
↳[Betty]→[Cheryl]
And the query cases I'm trying to solve for:
With ["Arthur", "Bob", "Charlie", "Dave"] AS Parentage
Match (p:Person WHERE p.Name="Arthur")
// ... somehow, return only the "Dave" node
With ["Arthur", "Betty"] AS Parentage
Match (p:Person WHERE p.Name="Arthur")
// ... somehow, return only the "Betty" node
With ["Arthur", "Mark"] AS Parentage
Match (p:Person WHERE p.Name="Arthur")
// ... somehow, don't return anything (because "Arthur" has no CHILD "Mark")
With ["Arthur", "Cheryl"] AS Parentage
Match (p:Person WHERE p.Name="Arthur")
// ... somehow, don't return anything (Note that "Cheryl" is not a direct CHILD of "Arthur")
Are the above scenarios possible to do as a Cypher query? I know that if I do something like this:
Match (p:Person WHERE p.Name="Arthur")-[r:CHILD*]->(b:Person)
RETURN r, a, b
It would provide me with all of the nodes and relationships, which I could then use application code to filter. But that seems like it could get expensive as nodes grow.