docker安装

neo4j browser
neo4j docker安装
docker pull neo4j
docker run —publish=7474:7474 —publish=7687:7687 —volume=$HOME/neo4j/data:/data neo4j
访问地址:loalhost:7474 默认账号密码:neo4j neo4j

命令

创建节点:CREATE (embiid: PLAYER {name: ‘Embiid’, height: ‘2.13m’, nationality: ‘Cameroon’})
创建另一节点和关系: MATCH (embiid:PLAYER{name:’Embiid’}) MERGE (embiid)-[:LIKES{since:’2014’}]->(Rihanna: SINGER{name:’Rihanna’, dob:’1988/2/20’,bloodType:’O’})
查询:MATCH(p:PLAYER)-[:LIKES]->(:SINGER{name:’Rihanna’}) RETURN p;
删除关系: MATCH (cc: Person)-[LIKES]-(c:Person) WHERE a.name = ‘zsd’ AND b.name = ‘dhy’ DELETE cc,c,LIKES
删除节点:MATCH (e: PLAYER) DELETE e
创建关系:MATCH (a:Person),(b:Person) WHERE a.name = ‘zsd’ AND b.name = ‘dhy’ CREATE (a)-[r:好友] -> (b) RETURN r

CREATE 创建 创建节点,关系和属性
MATCH 匹配 检索有关节点,关系和属性数据
RETURN 返回 返回查询结果
WHERE 哪里 提供条件过滤检索数据
DELETE 删除 删除节点和关系
REMOVE 移除 删除节点和关系的属性
ORDER BY以…排序 排序检索数据
SET 组 添加或更新标签

Neo4j CQL 函数

Aggregation 聚合 它们用于对CQL查询结果执行一些聚合操作。
Relationship 关系 他们用于获取关系的细节,如startnode,endnode等。

1.CREATE (a:Person{name:’zsd’,age:25,height:1.71,weight:70})
2.CREATE (a:Person{name:’dhy’,age:25,height:1.71,weight:70})
3.MATCH (a:Person),(b:Person) WHERE a.name = ‘zsd’ AND b.name = ‘dhy’ CREATE (a)-[r:好友] -> (b) RETURN r
4.MATCH (r) WHERE id(r) = 23 delete r RETURN r 通过id删除节点
5.match(emp) where emp.name =~’.haha.‘ return emp 模糊查询
6.match(a:Movie)where a.title is not null return a.title NULL值使用
7.match(a:Person) where a.name in [“zsd”,”llq”] return a in结果集查询
8.match(a:Person) where a.name=”TOM” set a.name=”Tom” return a set更改属性
9.MATCH (m:Movie) REMOVE m:Picture 删除标签
10.match(a:Person) return LOWER(a.name) as name LOWER/UPPER输出大小写转换
11.match(a:Person) return SUBSTRING(a.name,0,2) as name SUBSTRING输出子串截取
12.match(a) where a.name is not null return count()聚合函数-count结合return使用
13.其他聚合函数:age/sum/max/min 与match/return结合使用
14.MATCH (a)-[movie:喜欢]->(b) where a.name = ‘张飞’RETURN endNODE(movie) 关系函数endnode使用
15.其他关系函数:startnode/ID/TYPE
16.MATCH (a)-[movie:喜欢]->(b) where a.name = ‘张飞’RETURN type(movie) as type,id(movie) as id
17.索引:create index on :Person(name)/drop index on :Person(name)
18.UNIQUE约束:create constraint on (a:Movie) assert a.title is unique/drop constraint on (a:Movie) assert a.title is unique
19.shortestPath
20.WITH语句将分段的查询部分连接在一起,查询结果从一部分以管道形式传递给另外一部分作为开始点。
①match(i:Image)-[b:belong]->(p:Person) with p,i,b where p.name = “Tom” return p,i,b
②match(n) with n order by n.datetime limit 3 return collect(n.datetime) as a
21.match(a:Person)—(p:Image) return a —指??
22.FOREACH语句用于循环遍历结果集列表,然后做一些操作。
①MATCH p = (root { name: ‘Tom’ })-[r]-(A) FOREACH (n IN nodes(p)| SET n.marked = TRUE ) 设置路径上所有节点的marked属性为true值。
1.Movies and actors up to 4 “hops” away from Kevin Bacon? MATCH (bacon:Person{name:”KevinBacon”})-[
1..4]-(hollywood) RETURN DISTINCT hollywood.
2.Bacon path, the shortest path of any relationships to Meg Ryan? MATCH p=shortestPath( (bacon:Person {name:”Kevin Bacon”})-[*]-(meg:Person {name:”Meg Ryan”}) ) RETURN p
3.Delete all nodes, and their relationships!
MATCH (n) DETACH DELETE n