Query Template - Create
Generate nodes and relationships
Using Data | From a node labeled "{{nodeLabelA}}" with a property called "{{propertyKeyA}}" which has value "{{propertyValueA}}" , through a relationship of type "{{relationshipType}}" to another node labeled "{{nodeLabelB}}" with a property called "{{propertyKeyB}}" which has value "{{propertyValueB}}" |
---|---|
Create |
Create a "{{nodeLabelA}}" node
with a property called "{{propertyKeyA}}"
that has value "{{propertyValueA}}". (Or create Node B)
CREATE (n:{{nodeLabelA | tickitize}} { {{propertyKeyA | tickitize}}: '{{propertyValueA}}' }) RETURN n CREATE (n:{{nodeLabelB | tickitize}} { {{propertyKeyB | tickitize}}: '{{propertyValueB}}' }) RETURN n |
Relate |
From a "{{nodeLabelA}}" node
with a "{{propertyKeyA}}" property
of "{{propertyValueA}}"
create a "{{relationshipType}}"
relationship to a "{{nodeLabelB}}" with "{{propertyKeyB}}" value "{{propertyValueB}}".
MATCH (a:{{nodeLabelA | tickitize}} { {{propertyKeyA | tickitize}}: '{{propertyValueA}}' }), (b:{{nodeLabelB | tickitize}} { {{propertyKeyB | tickitize}}: '{{propertyValueB}}' }) CREATE (a)-[:{{relationshipType | tickitize}}]->(b) |
Merge node |
Find or create a "{{nodeLabelA}}" node
with "{{propertyKeyA}}" of "{{propertyValueA}}".
MERGE (n:{{nodeLabelA | tickitize}} { {{propertyKeyA | tickitize}}: '{{propertyValueA}}' }) RETURN n |
Merge relationship |
Find or create a relationship from a "{{nodeLabelA}} with "{{propertyKeyA}}" of "{{propertyValueA}}"
through a "{{relationshipType}}" relationship
to a "{{nodeLabelB}}" node with "{{propertyKeyB}}" of "{{propertyValueB}}".
MATCH (a:{{nodeLabelA | tickitize}} { {{propertyKeyA | tickitize}}: '{{propertyValueA}}' }), (b:{{nodeLabelB | tickitize}} { {{propertyKeyB | tickitize}}: '{{propertyValueB}}' }) MERGE (a)-[:{{relationshipType}}]->(b) |
Query Template - Find
Find data using common graph patterns
Using Data | From a node labeled "{{nodeLabelA}}" with a property called "{{propertyKeyA}}" which has value "{{propertyValueA}}" , through a relationship of type "{{relationshipType}}" to another node labeled "{{nodeLabelB}}" with a property called "{{propertyKeyB}}" which has value "{{propertyValueB}}" |
---|---|
Find one |
Find a node labeled "{{nodeLabelA}}"
with a property called "{{propertyKeyA}}"
that has value "{{propertyValueA}}".
MATCH (n:{{nodeLabelA | tickitize}} { {{propertyKeyA | tickitize}}: '{{propertyValueA}}' }) RETURN n |
Find related neighbors |
From a "{{nodeLabelA}}" node
with a "{{propertyKeyA}}"
of "{{propertyValueA}}"
find neighbors related by "{{relationshipType}}".
MATCH (n:{{nodeLabelA| tickitize}} { {{propertyKeyA | tickitize}}: '{{propertyValueA}}' })-[:{{relationshipType | tickitize}}]-(neighbors) RETURN n,neighbors |
Variable length paths |
From a "{{nodeLabelA}}" node
with a "{{propertyKeyA}}"
of "{{propertyValueA}}"
follow "{{relationshipType}}" relationships up to {{relationshipDepth}} hops away.
MATCH (n:{{nodeLabelA}} { {{propertyKeyA | tickitize}}: '{{propertyValueA}}' })-[:{{relationshipType | tickitize}}*1..{{relationshipDepth}}]-(neighbors) RETURN n, collect(DISTINCT neighbors) |
Shortest path |
From a "{{nodeLabelA}}" node
with a "{{propertyKeyA}}"
of "{{propertyValueA}}"
find the shortest "{{relationshipType}}" path to
a "{{nodeLabelB}}" node with "{{propertyKeyB}}" of "{{propertyValueB}}"
MATCH p=shortestPath( (a:{{nodeLabelA | tickitize}} { {{propertyKeyA | tickitize}}: '{{propertyValueA}}' })-[:{{relationshipType | tickitize}}]-(b:{{nodeLabelB | tickitize}} { {{propertyKeyB | tickitize}}: '{{propertyValueB}}'}) ) RETURN p |
Next steps
More code
- Northwind Graph - from RDBMS to graph
- Movie Graph - common ad-hoc queries
- Cypher - query language fundamentals