Search code examples
neo4jcypher

How to make a 'blueprint' of all possible relationships and nodes in Neo4J with Cypher?


What I want to create is a blueprint of my datamodel. What I mean with blueprint is a newly created datamodel, where every node is created only once; every node with a unique label (with eiter none, one or multiple labels) from my real database must be copied and shown once.

For every unique node in this blueprint, I also need a relationship blueprint. So for every different relationship (either by name, direction or connected nodes) I also need only one representation.

Example: Say i have have 4 nodes, of which 2 are Persons and 2 are Companies; then in the blueprint only 2 nodes are shown. These are the relationships:

(c)-[:LIKES]->(p)
(c)-[:LIKES]->(p)
(c)-[:LIKES]->(c)
(c)-[:LIKES]->(c)
(p)<-[DISLIKS]-(c)

These relationships show 3 unique relationships, based on name, direction and nodes connected. So for this blueprint, the outcome must be 2 unique nodes with 3 unique relationships.

I've been struggling with the code to realize this for a while. Any suggestions much appreciated!


Solution

  • It seems the Neo4j built-in procedure db.schema.visualization() is what you're looking for : https://neo4j.com/docs/operations-manual/current/reference/procedures/#procedure_db_schema_visualization

    Example :

    enter image description here