https://neo4j.com/docs/cypher-manual/current/clauses/match/
*Example Graph
CREATE
(charlie:Person {name: 'Charlie Sheen'}),
(martin:Person {name: 'Martin Sheen'}),
(michael:Person {name: 'Michael Douglas'}),
(oliver:Person {name: 'Oliver Stone'}),
(rob:Person {name: 'Rob Reiner'}),
(wallStreet:Movie {title: 'Wall Street'}),
(charlie)-[:ACTED_IN {role: 'Bud Fox'}]->(wallStreet),
(martin)-[:ACTED_IN {role: 'Carl Fox'}]->(wallStreet),
(michael)-[:ACTED_IN {role: 'Gordon Gekko'}]->(wallStreet),
(oliver)-[:DIRECTED]->(wallStreet),
(thePresident:Movie {title: 'The American President'}),
(martin)-[:ACTED_IN {role: 'A.J. MacInerney'}]->(thePresident),
(michael)-[:ACTED_IN {role: 'President Andrew Shepherd'}]->(thePresident),
(rob)-[:DIRECTED]->(thePresident),
(martin)-[:FATHER_OF]->(charlie)
1. Outgoing relationships
관계의 방향을 정확히 해야하는 경우 --> or <-- 를 사용
#label이 Person이고 name이 Oliver Stone인 노드에서 나가는 관계로 연결된 노드 반환
MATCH (:Person {name: 'Oliver Stone'})-->(movie)
RETURN movie.title
2. Directed relationships and variable
관계 type을 반환
#Oliver Stone 노드에서 나가는 관계 type을 반환
MATCH (:Person {name: 'Oliver Stone'})-[r]->(movie)
RETURN type(r)
3. Match on relationship type
관계 type을 알고 있는 경우 :을 사용하여 type을 지정
#Wall Street 노드와 ACTED_IN 관계인 노드들 반환
MATCH (wallstreet:Movie {title: 'Wall Street'})<-[:ACTED_IN]-(actor)
RETURN actor.name
4. Match on multiple relationship types
#Wall Street 노드와 ACTED_IN or DIRECTED 관계인 노드들 반환
MATCH (wallstreet {title: 'Wall Street'})<-[:ACTED_IN|DIRECTED]-(person)
RETURN person.name
5. Match on relationship type and use a variable
#Wall Street 노드와 ACTED_IN한 관계인 노드의 관계 속성 반환
MATCH (wallstreet {title: 'Wall Street'})<-[r:ACTED_IN]-(actor)
RETURN r.role
'DKE > Neo4j' 카테고리의 다른 글
[Neo4j] MATCH (Shortest path) / 2023.02.07 (0) | 2023.02.07 |
---|---|
[Neo4j] MATCH (Relationships in depth) / 2023.02.07 (0) | 2023.02.07 |
[Neo4j] MATCH (Basic node finding) / 2023.02.06 (0) | 2023.02.06 |
[Neo4j] REMOVE / 2023.02.03 (0) | 2023.02.03 |
[Neo4j] SET / 2023.02.03 (0) | 2023.02.03 |