Neo4j 系列
1、图数据库 Neo4j 学习随笔之基础认识
2、图数据库 Neo4j 学习随笔之核心内容
3、图数据库 Neo4j 学习随笔之基础操作
4、图数据库 Neo4j 学习随笔之高级操作
5、图数据库 Neo4j 学习之JAVA-API操作
6、图数据库 Neo4j 学习之SpringBoot整合
Neo4j - CQL 使用
Neo4j 的 Cypher 语言是为处理图形数据库而构建的,CQL 代表 Cypher 查询语言。
类似 关系型数据库的 SQL 语言。
文章目录
前言
Neo4j 高级语言操作。
一、INDEX索引
1.1 索引创建
1.1.1 创建普通索引
在数据量大的情况下可以创建索引提高查询效率。
create index on :loveperson (name)
1.1.2 删除普通索引
drop index on:loveperson (name)
1.2 唯一索引
1.2.1 创建唯一索引
限制每一个标签的数据值是唯一的,Neo4j 对 Node 或者 Relationship 的属性添加 UNIQUE 约束。
create constraint on (n:loveperson) assert n.name is unique
1.2.2 删除唯一索引
drop constraint on (n:loveperson) assert n.name is unique
二、常用函数
2.1 DISTINCT(去重)
match (n:loveperson) return distinct(n.name)
2.2 字符串函数
2.2.1 Upper(转大写)
match (n:loveperson) return upper(n.name) as name
2.2.2 Lower(转小写)
match (n:loveperson) where id(n) = 130 return lower(n.name)
2.2.3 Substring(截取字符串)
match (n:loveperson) where id(n) = 117 return substring(n.name, 0, 3) as name
2.2.4 Replace(替换字符串)
把我的名字ste 替换成 Y, 就是 Yphen
match (n:loveperson) where id(n) = 117 return replace(n.name, 'ste', 'Y') as name
2.3 Aggregation (聚合)
和 sql 里面的 group by函数类似,Neo4j 提供了聚合函数的子句。
2.3.1 Count(统计行数)
match (n:loveperson) return count(n.name) as name_count
2.3.2 Max(最大值)
match (n:loveperson) return max(n.age) as max_age
2.3.3 Min(最小值)
match (n:loveperson) return min(n.age) as min_age
2.3.4 Sum(总和)
match (n:loveperson) return sum(n.age) as sum_age
2.3.5 Avg(平均值)
match (n:loveperson) return avg(n.age) as avg_age
2.4 Relationship (关系)
2.4.1 Startnode(找到关系的开始节点)
match (n:loveperson)-[rel]->(m:loveperson) return startnode(rel)
2.4.2 Endnode(找到关系的结束节点)
match (n:loveperson)-[rel]->(m:loveperson) return endnode(rel)
2.4.3 Id (知道关系的id)
match (n:loveperson)-[rel]->(m:loveperson) return id(rel)
2.4.4 Type(知道关系的类型)
match (n:loveperson)-[rel]->(m:loveperson) return type(rel)
三、 数据备份与恢复
3.1 数据备份
.\neo4j-admin.bat dump --database=graph.db --to=D:\loveperson.dump
3.2 恢复数据
.\neo4j-admin.bat load --database=graph.db --from=D:\loveperson.dump --force
四、总结
Neo4j 操作,Cypher 语法相对简单,到这里基本 neo4j 操作和高级操作就差不多了,接下来开始用java 操作 Neo4j 图形数据库。