docker创建neo4j命令
docker run -d --name graphRag -p 74:7474 -p 75:7687 -v /tools/docker/neo4j/data:/data -v /tools/docker/neo4j/logs:/logs -v /tools/docker/neo4j/conf:/var/lib/neo4j/conf -v /tools/docker/neo4j/import:/var/lib/neo4j/import --env NEO4J_AUTH=neo4j/password neo4j:tag
1 描述关系
(节点)<-[:关系]-(节点)->[:关系]->(节点)
2 create
用于创建节点和关系。
- 创建节点:CREATE (node:Label {property: value})
- 创建关系:CREATE (node1)-[:RELATIONSHIP]->(node2)
// 创建节点
create (node:Person {name:'SQ',gender:'男'})
//创建关系
create (节点1)-[:关系]->(节点2)
3 match 和 return
match 用于检索符合指定模式的节点和关系。
return 用于返回查询结果。
- 返回匹配节点:MATCH (node:Label {property: value}) RETURN node
- 返回匹配节点间的关系 MATCH (node1)-[:RELATIONSHIP]->(node2) RETURN node1, node2
- 返回节点的属性: match (node:label) RETURN node.property
- 返回多个节点:RETURN node1, node2
//检索节点:
MATCH (node:Person) RETURN node
//检索关系:
MATCH (john)-[:FRIENDS_WITH]->(mary) RETURN john, mary
//返回节点的属性:
MATCH (node:Person) RETURN node.name
//返回多个节点:
RETURN john, mary
4 where
用于指定查询条件。
- 根据节点属性查询:MATCH (node:Label) WHERE node.property = value RETURN node
- 根据节点间的关系查询:MATCH (node1)-[:RELATIONSHIP]->(node2) WHERE node1.property = value RETURN node1, node2
//指定属性条件:
MATCH (node:Person) WHERE node.name = "John" RETURN node
//关系条件:
MATCH (john)-[:FRIENDS_WITH]->(mary)
WHERE john.age > 18 RETURN john, mary
5 delete
用于删除节点和关系。
- 删除节点:DELETE node
- 删除关系:match (node1)-[r:RELATIONSHIP]->(node2) delete r
//删除节点:
MATCH (node:Person) WHERE node.name = "John" DELETE node
//删除关系:
MATCH (john)-[r:FRIENDS_WITH]->(mary) DELETE r
6 set
用于更新节点和关系的属性。
- SET node.property = value
- SET (node1)-[:RELATIONSHIP]->(node2).property = value
//更新节点属性:
MATCH (node:Person) WHERE node.name = "John" SET node.age = 30
//更新关系属性:
MATCH (john)-[r:FRIENDS_WITH]->(mary) SET r.since = 2022
7 merge
用于合并节点和关系,如果不存在则创建。
- MERGE (node:Label {property: value})
- MERGE (node1)-[:RELATIONSHIP]->(node2)
//合并节点:
MERGE (node:Person {name: "John"})
//合并关系:
MERGE (john)-[:FRIENDS_WITH]->(mary)
8 load csv
加载数据(默认加载文件位置在安装路径下的import 文件夹)
//语法格式
LOAD CSV WITH HEADERS FROM "file:///path/to/file.csv" AS row
CREATE (node:Label)
SET node.property1 = row.column1, node.property2 = row.column2
//eg
load csv from "file:///person.csv" as row
create (:person {name:row[0],age:row[1],gender:row[2]})