Queries
- Display database schema
- Basically displaying all types of nodes and relationships between each type of node
CALL db.schema.visualization();
- Data import
- See the stackoverflow sample dataset for JSON import from url
- Data Import - Developer Guides (neo4j.com)
Basic Queries
Find labels and their frequencies
Label is basically node name/type.
MATCH (n)
RETURN labels(n) as label, count(*) as freq
ORDER BY freq DESC;
Find all relationship types and their frequencies
MATCH ()-[r]->()
RETURN type(r) as type, count(*) as freq
ORDER BY freq DESC;
()-[r]->()
is used to express relationship. The middle term is relationship.
Left and right of the relationship are both nodes.
(A)-[reads]->(B)
means A reads B. The relation is the same as the direction of the arrow.
Sorting by Attribute Count
What are the most popular tags?
MATCH (q:Question)-[:TAGGED]->(t:Tag)
RETURN t.name, count(q) AS questions
ORDER BY questions DESC
LIMIT 5;
Find all question tags, and count question for each tag.
Path Finding
Find all shortest paths between 2 users with whatever relationships in between.
MATCH path = allShortestPaths(
(u1:User {display_name:"alexanoid"})-[*]-(u2:User {display_name:"InverseFalcon"}))
RETURN path LIMIT 1;