0

I'm using neo4j and I build a large graph that has a lot of subgraph. For example, in the pic below there are 4 subgraphs. enter image description here

So how can I get 4 groups of nodes by cypher query?

I'm using neo4j 3.0

milowang
  • 101
  • 2
  • 10

2 Answers2

1

You can make use of Strongly connected components algorithm in the Graph data science library (GDS - https://github.com/neo4j/graph-data-science) for Neo4j. The documentation is available at - https://neo4j.com/docs/graph-data-science/current/algorithms/strongly-connected-components/ You can create a sub-graph using node projection or other methods are available in the docs and as the name suggests, the algorithm will create separate communities in your graph, by using strongly connected component logic (https://en.wikipedia.org/wiki/Strongly_connected_component), and you will have nodes separated out like you want.

-1

If you want to display all node along with all relationships, you can use a quick and easy cypher query at your disposal. Assuming there are no restrictions applicable to your account:

MATCH (n) RETURN n
Raunak Jhawar
  • 1,541
  • 1
  • 12
  • 21
  • no, I want to return [node1, node2, node3], [node4, node5], [node6, node7, node8] ,each list represent a subgraph – milowang Apr 11 '17 at 09:04
  • try something like this, not very optimized, but it might work ```MATCH (a)-[:synonyms*]->(b) WITH collect(distinct(b)) as islands RETURN distinct(islands)``` – Tomaž Bratanič Apr 11 '17 at 09:20