Skip to content

Instantly share code, notes, and snippets.

@davidrapin
Created March 5, 2021 10:15
Show Gist options
  • Save davidrapin/eb69215c23495c4984a507fc5aa3ac4e to your computer and use it in GitHub Desktop.
Save davidrapin/eb69215c23495c4984a507fc5aa3ac4e to your computer and use it in GitHub Desktop.
Generate edge types (Neo4j Cypher)
// edgeCount: the number of edges with a unique edge-type to generate
// sourceNodeId: ID of the node to be used as source for all generated edges
// targetNodeId: ID of the node to be used as target for all generated edges
// prefix: the edge-type prefix to use for generated edge-types
WITH 100 as edgeCount, 1 as sourceNodeId, 2 as targetNodeId, "edge_type_prefix_" as prefix
MATCH (a), (b) WHERE id(a) = sourceNodeId and id(b) = targetNodeId
WITH range(1, edgeCount) as xx, a, b
UNWIND xx AS x
CALL apoc.create.relationship(a, prefix + toString(x), {property: x}, b) YIELD rel
RETURN a, b, rel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment