Neo4J: find a sub-graph of arbitrary depth with no

2019-09-09 02:08发布

问题:

How to build a Neo4J query that:

1) Will return all nodes in a sub-graph of arbitrary depth with nodes connected by a given set of relations?

For example in Cypher-like syntax:

MATCH (*)-[r1:FRIEND_OF AND r2:COLLEAGUE_WITH]->(*) RETURN * 

回答1:

This query will return just the nodes, as you stated in your question:

MATCH (n)-[:FRIEND_OF|COLLEAGUE_WITH*]->(m)
RETURN n, m;

If you also want the relationships:

MATCH (n)-[r:FRIEND_OF|COLLEAGUE_WITH*]->(m)
RETURN n, r, m;