I am trying create a query in which starts with the blue nodes called "Analytical Units". The query will get all sub-nodes unless it runs into a node which "overrides" the relationship by being directly attached to a different analytical unit. Any help would be appreciated!
1
votes
Can you expand on this? As in, given the graph you linked to, walk us through the operations you expect a correct query to do, and the expected output.
- InverseFalcon
Aside: you seem to have relationship types that have opposite directionality but always exist between between the same nodes. This redundancy is not necessary in neo4j, as you can easily navigate a relationship in either direction.
- cybersam
@InverseFalcon Sure, so lets say that I queried with a starting node of "Bank of America" ... one of the blue nodes... I want to get everything connected to it boxed in in red. The idea is that everything beneath it would "Inherit" the "Analytically A Part Of" relationship unless it runs into a node that explicitly defines that relationship to somewhere else. I am not sure maybe its best practice to give every node that explicit relationship.
- patrickb19
@cybersam thanks for this tip, I will remove the redundancy.
- patrickb19
Do you only care about red nodes as "sub-nodes"? The green nodes "Barnett Bank" and "Bank South" would seem to qualify as "sub-nodes" of either blue node, depending on which blue node you start traversing from.
- cybersam
1 Answers
1
votes
Does this query work for you?
It should return each Blue node (that has a path to any Red nodes) and its "sub-nodes" (along each of those paths), ignoring paths in which any sub-node (except the first) has an incoming ANALYTICALLY_COMPOSED relationship:
MATCH (a:Blue)-[:ANALYTICALLY_COMPOSED]->(b)
MATCH p=(b)-[rels*]-(:Red)
WITH a, NODES(p) AS subnodes
WHERE NONE(n IN subnodes[1..] WHERE ()-[:ANALYTICALLY_COMPOSED]->(n))
RETURN a, subnodes;
