Last active
March 8, 2018 00:59
-
-
Save rdkls/3766b2f43f62f04ccaeae3d7e824e330 to your computer and use it in GitHub Desktop.
neo4j create schema based on existing nodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate an overview / schema of a graph database | |
// Creates a node for each node label found in the graph, | |
// relating these to each other for each type of relationship found in the graph | |
// (apoc call required to create rel with dynamic type) | |
MATCH (a)-[r]->(b) | |
WITH head(labels(a)) AS l, head(labels(b)) AS l2, type(r) AS rel_type, count(*) as num_links | |
merge (aMeta:Meta {label: l}) | |
merge (bMeta:Meta {label: l2}) | |
with aMeta, bMeta, rel_type, num_links | |
call apoc.create.relationship(aMeta, rel_type, {num_links: num_links}, bMeta) yield rel | |
with aMeta, bMeta | |
return aMeta, bMeta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment