logo资料库

Neo4j中文使用手册以及例子.doc

第1页 / 共560页
第2页 / 共560页
第3页 / 共560页
第4页 / 共560页
第5页 / 共560页
第6页 / 共560页
第7页 / 共560页
第8页 / 共560页
资料共560页,剩余部分请下载后查看
第 1 章 Neo4j的亮点
第 2 章 图数据库概要
2.1. 什么是图数据库?
2.1.1. 一个图由无数的节点和关系组成
2.1.2. 关系将图各个部分组织起来
2.1.3. 用 Traversal 进行数据库查询
2.1.4. 为节点和关系建立索引
2.1.5. Neo4j是一个图数据库
2.2. 比较各种数据库模型
2.2.1. 从图数据库转换成 RDBMS
2.2.3. 从图数据库转换成列数据库
2.2.4. 从图数据库转换成文档型数据库
3.1. 节点
3.2. 关系
3.3. 属性
3.4. 路径
3.5. 遍历(Traversal)
部分 II. 教程
第 4 章 在Java应用中使用Neo4j
4.1. 将Neo4j引入到你的项目工程中
4.1.1. 增加Neo4j的库文件到构造路径中
4.1.2. 将Neo4j作为一个依赖添加
Maven
Eclipse and Maven
Ivy
Gradle
4.1.3. 启动和停止
4.2. 你好,世界
4.2.1. 准备图数据库
4.2.2. 在一个事务中完成多次写数据库操作
4.2.3. 创建一个小型图数据库
4.2.4. 打印结果
4.2.5. 移除数据
4.2.6. 关闭图数据库
4.3. 带索引的用户数据库
4.4. 基本的单元测试
4.5. 遍历查询
4.5.1. 黑客帝国
游走一个有序路径
4.5.2. 老的遍历查询 API
4.5.3. 在遍历查询中的唯一路径
4.5.4. 社交网络
简单的社交模型
状态图实例
活动流
4.6. 领域实体
4.7. 图算法范例
4.8. 读取一个管理配置属性
4.9. OSGi配置
4.9.1. Simple OSGi Activator 脚本
4.10. 在Java中执行Cypher查询
第 5 章 Neo4j远程客户端库
5.1. 由社区贡献的Neo4j REST客户端
5.2. 在Java中如何使用REST API
5.2.1. 通过 REST API 创建一个图数据库
5.2.2. 启动图数据库服务器
5.2.3. 创建一个节点
5.2.4. 增加属性
5.2.5. 增加关系
5.2.6. 给关系增加属性
5.2.7. 从图数据库中查询数据
5.2.8. 喔,是这样吗?==
5.2.9. 下一步计划是什么呢?
5.2.10. 附录:代码
第 6 章 遍历查询框架
6.1. 主要观点
6.2. 遍历查询框架 Java API
6.2.1. TraversalDescription
Relationships
6.2.2. Evaluator
6.2.3. Traverser
6.2.4. Uniqueness
Depth First / Breadth First
6.2.5. Order — 如何穿过分支呢?
6.2.6. BranchSelector
BranchOrderingPolicy
TraversalBranch
6.2.7. Path
6.2.8. PathExpander/RelationshipExpander
6.2.9. Expander
6.2.10. 如何使用遍历查询框架
第 7 章 数据模型范例
7.1. 在图数据库中的用户角色模型
7.1.1. 得到管理员
7.1.2. 得到一个用户的组成员
7.1.3. 获取所有的用户组
7.1.4. 找到所有用户
7.2. 在图数据库中的ACL结构模型
7.2.1. 通用方法
构建ACL
自顶向下的遍历
范例
7.2.2. 读取权限范例
在目录结构中查找所有的文件
谁拥有哪些文件?
谁可以访问这个文件?
7.3. 链表
7.4. 超边
7.4.1. Find Groups
7.4.2. Find all groups and roles for a user
7.4.3. Find common groups based on shared roles
7.5. 基于社交邻居的朋友查找
7.6. Co-favorited places
7.6.1. Co-favorited places — users who like x also
7.6.2. Co-Tagged places — places related through t
7.7. Find people based on similar favorites
7.8. Find people based on mutual friends and group
7.9. Find friends based on similar tagging
7.10. Multirelational (social) graphs
7.11. Boosting recommendation results
7.12. Calculating the clustering coefficient of a
7.13. Pretty graphs
7.13.1. Star graph
7.13.2. Wheel graph
7.13.3. Complete graph
7.13.4. Friendship graph
7.14. A multilevel indexing structure (path tree)
7.14.1. Return zero range
7.14.2. Return the full range
7.14.3. Return partly shared path ranges
7.15. Complex similarity computations
7.15.1. Calculate similarities by complex calculat
第 8 章 多语言支持
第 9 章 在Python应用中使用Neo4j
9.1. 你好,世界!
9.2. 一个使用遍历查询和索引的范例应用
9.2.1. 域逻辑
9.2.2. 创建数据并返回他们
第 10 章 扩展Neo4j服务器
10.1. 服务器插件
10.2. 非托管扩展
部分 III. 参考
第 11 章 性能
11.1. 数据安全性
某些数据可能需要不受未经授权的访问 (如盗窃、 修改)。Neo4j 不明确,处理数据加密,但支持一切
11.2. 数据完整性
11.2.1. 核心图引擎
11.2.2. 不同的数据源
在一些情况下,与其他系统结合了为了实现最佳性能非图形执行查找的核心图形引擎。例如,11.3. 数据集
大多数企业主要依靠关系数据库来存储它们的数据,但这可能会导致性能限制。在某些情况下,可以作为扩展使用
11.3.1. Event-based Synchronization
11.3.2. Periodic Synchronization
另一个可行的方案是通过某种形式的 SQL 查询 Neo4j 到 RDBMS 的最新变化的定期出口。这
11.3.3. Periodic Full Export/Import of Data
11.4. 可用性和可靠性
11.4.1. Operational Availability
Online backup (Cold spare)
Online Backup High Availability (Hot spare)
High Availability cluster
11.4.2. Disaster Recovery/ Resiliency
Prevention
Detection
Correction
11.5. 容量
11.5.1. File Sizes
11.5.2. Read speed
11.5.4. Data size
第 12 章 事务管理
12.1. Interaction cycle
12.2. Isolation levels
12.3. Default locking behavior
12.4. Deadlocks
12.5. Delete semantics
12.6. Creating unique nodes
12.6.1. Single thread
12.6.2. Get or create
12.6.3. Pessimistic locking
12.7. Transaction events
第 13 章 数据导入
13.1. 批量插入
13.1.1. Batch Inserter Examples
13.1.2. Batch Graph Database
13.1.3. 批量插入数据
Best practices
第 14 章 索引
14.1. Introduction
14.2. Create
14.3. Delete
14.4. Add
14.5. Remove
14.6. Update
14.7. Search
14.7.1. Get
14.7.2. Query
14.8. Relationship indexes
14.9. Scores
14.10. Configuration and fulltext indexes
14.11. Extra features for Lucene indexes
14.11.1. Numeric ranges
14.11.2. Sorting
14.11.3. Querying with Lucene Query objects
14.11.4. Compound queries
14.11.5. Default operator
14.11.6. Caching
14.12. Automatic Indexing
14.12.1. Configuration
14.12.2. Search
14.12.3. Runtime Configuration
14.12.4. Updating the Automatic Index
第 15 章 Cypher查询语言
15.1. 操作符
15.2. 表达式
15.2.1. Note on string literals
15.3. 参数
15.4. 标识符
15.5. 备注
15.6. 更新图数据库
15.6.1. The Structure of Updating Queries
15.6.2. Returning data
15.7. 事务
15.8. Patterns
15.8.1. Patterns for related nodes
15.8.2. Working with relationships
15.8.3. Optional relationships
15.8.4. Controlling depth
15.8.5. Assigning to path identifiers
15.8.6. Setting properties
15.8.7. Start
Node by id
Relationship by id
Multiple nodes by id
All nodes
Node by index lookup
Relationship by index lookup
Node by index query
Multiple starting points
15.8.8. Match
Introduction
Related nodes
Outgoing relationships
Directed relationships and identifier
Match by relationship type
Match by multiple relationship types
Match by relationship type and use an identifier
Relationship types with uncommon characters
Multiple relationships
Variable length relationships
Relationship identifier in variable length relatio
Zero length paths
Optional relationship
Optional typed and named relationship
Properties on optional elements
Complex matching
Shortest path
All shortest paths
Named path
Matching on a bound relationship
Match with OR
15.8.9. Where
Boolean operations
Filter on node property
Regular expressions
Escaping in regular expressions
Case insensitive regular expressions
Filtering on relationship type
Property exists
Default true if property is missing
Default false if property is missing
Filter on null values
Filter on patterns
Filter on patterns using NOT
IN operator
15.8.10. Return
Return nodes
Return relationships
Return property
Return all elements
Identifier with uncommon characters
Column alias
Optional properties
Unique results
15.8.11. Aggregation
Introduction
COUNT
Count nodes
Group Count Relationship Types
Count entities
Count non-null values
SUM
AVG
MAX
MIN
COLLECT
DISTINCT
15.8.12. Order by
Order nodes by property
Order nodes by multiple properties
Order nodes in descending order
Ordering null
15.8.13. Limit
Return first part
15.8.14. Skip
Skip first three
Return middle two
15.8.15. With
Filter on aggregate function results
Alternative syntax of WITH
15.8.16. Create
15.8.17. Create single node
15.8.18. Create single node and set properties
15.8.19. Return created node
15.8.20. Create a relationship between two nodes
15.8.21. Create a relationship and set properties
15.8.22. Create a full path
15.8.23. Create single node from map
15.8.24. Create multiple nodes from maps
15.8.25. Create Unique
15.8.26. Create relationship if it is missing
15.8.27. Create node if missing
15.8.28. Create nodes with values
15.8.29. Create relationship with values
15.8.30. Describe complex pattern
15.8.31. Set
15.8.32. Set a property
15.8.33. Delete
15.8.34. Delete single node
15.8.35. Remove a node and connected relationships
15.8.36. Remove a property
15.8.37. Foreach
15.8.38. Mark all nodes along a path
15.8.39. Functions
15.8.40. Predicates
ALL
ANY
NONE
SINGLE
15.8.41. Scalar functions
LENGTH
TYPE
ID
COALESCE
HEAD
LAST
15.8.42. Collection functions
NODES
RELATIONSHIPS
EXTRACT
FILTER
TAIL
RANGE
15.8.43. Mathematical functions
ABS
ROUND
SQRT
SIGN
15.8.44. 兼容性
15.8.45. 从SQL到Cypher查询
Start
Match
Where
Return
第 16 章 图形算法
16.1. Introduction
第 17 章 Neo4j服务器
17.1. 服务器安装
17.1.1. As a Windows service
17.1.2. Linux Service
17.1.4. Multiple Server instances on one machine
First instance
Second instance (testing, development)
17.2. 服务器配置
17.2.1. 重要的服务器配置参数
17.2.2. Neo4j数据库性能配置
17.2.3. 服务器日志配置
17.2.4. HTTP日志配置
17.2.5. 其他配置选项
启用来自垃圾收集器日志记录
在Webadmin中禁用控制台类型
17.3. 设置远程调试
17.5. 服务器性能优化
17.5.1. Specifying Neo4j tuning properties
17.5.2. Specifying JVM tuning properties
17.6. 在云计算环境中的服务器安装
17.7. Heroku
第 18 章 REST API
18.1. Service root
18.1.1. Get service root
18.2. Streaming
18.3. Cypher queries
18.3.1. Send queries with parameters
18.3.2. Send a Query
18.3.3. Return paths
18.3.4. Nested results
18.3.5. Server errors
18.4. Nodes
18.4.1. Create Node
18.4.2. Create Node with properties
18.4.3. Get node
18.4.4. Get non-existent node
18.4.5. Delete node
18.4.6. Nodes with relationships can not be delete
18.5. Relationships
18.5.1. Get Relationship by ID
18.5.2. Create relationship
18.5.3. Create a relationship with properties
18.5.4. Delete relationship
18.5.5. Get all properties on a relationship
18.5.6. Set all properties on a relationship
18.5.7. Get single property on a relationship
18.5.8. Set single property on a relationship
18.5.9. Get all relationships
18.5.10. Get incoming relationships
18.5.11. Get outgoing relationships
18.5.12. Get typed relationships
18.5.13. Get relationships on a node without relat
18.6. Relationship types
18.6.1. Get relationship types
18.7. Node properties
18.7.1. Set property on node
18.7.2. Update node properties
18.7.3. Get properties for node
18.7.4. Property values can not be null
18.7.5. Property values can not be nested
18.7.6. Delete all properties from node
18.7.7. Delete a named property from a node
18.8. Relationship properties
18.8.1. Update relationship properties
18.8.2. Remove properties from a relationship
18.8.3. Remove property from a relationship
18.8.4. Remove non-existent property from a relati
18.8.5. Remove properties from a non-existing rela
18.8.6. Remove property from a non-existing relati
18.9. Indexes
18.9.1. Create node index
18.9.2. Create node index with configuration
18.9.3. Delete node index
18.9.4. List node indexes
18.9.5. Add node to index
18.9.6. Remove all entries with a given node from
18.9.7. Remove all entries with a given node and k
18.9.8. Remove all entries with a given node, key
18.9.9. Find node by exact match
18.9.10. Find node by query
18.10. Unique Indexes
18.10.1. Create a unique node in an index
18.10.2. Create a unique node in an index (the cas
18.10.3. Add a node to an index unless a node alre
18.10.4. Create a unique relationship in an index
18.10.5. Add a relationship to an index unless a r
18.11. Automatic Indexes
18.11.1. Find node by exact match from an automati
18.11.2. Find node by query from an automatic inde
18.12. Configurable Automatic Indexing
18.12.1. Create an auto index for nodes with speci
18.12.2. Create an auto index for relationships wi
18.12.3. Get current status for autoindexing on no
18.12.4. Enable node autoindexing
18.12.5. Lookup list of properties being autoindex
18.12.6. Add a property for autoindexing on nodes
18.13. Traversals
18.13.1. Traversal using a return filter
18.13.2. Return relationships from a traversal
18.13.3. Return paths from a traversal
18.13.4. Traversal returning nodes below a certain
18.13.5. Creating a paged traverser
18.13.6. Paging through the results of a paged tra
18.13.7. Paged traverser page size
18.13.8. Paged traverser timeout
18.14. Built-in Graph Algorithms
18.14.1. 查找所有的最短路径
18.14.2. 查找节点之间的最短路径之一
18.14.3. 在关系上执行类似权重 Dijkstra 算法
18.14.4. 在关系上执行权重 Dijkstra 算法
18.15. Batch operations
18.15.1. 在批处理中执行多个操作
18.15.2. 较早前在同一个批处理作业中创建的项目,请参阅
18.15.3. 批处理流中执行多个操作
18.16. WADL Support
18.17. Cypher插件
18.17.1. Send a Query
18.17.2. Return paths
18.17.3. Send queries with parameters
18.17.4. Server errors
18.18. Gremlin Plugin
18.18.1. Send a Gremlin Script - URL encoded
18.18.2. Load a sample graph
18.18.3. Sort a result using raw Groovy operations
18.18.4. Send a Gremlin Script - JSON encoded with
18.18.5. Returning nested pipes
18.18.6. Set script variables
18.18.7. Send a Gremlin Script with variables in a
18.18.8. Return paths from a Gremlin script
18.18.9. Send an arbitrary Groovy script - Lucene
18.18.10. Emit a sample graph
18.18.11. HyperEdges - find user roles in groups
18.18.12. Group count
18.18.13. Collect multiple traversal results
18.18.14. Collaborative filtering
18.18.15. Chunking and offsetting in Gremlin
18.18.16. Modify the graph while traversing
18.18.17. Flow algorithms with Gremlin
18.18.18. Script execution errors
第 19 章 在Python中使用Neo4j嵌入模式
19.1. 安装
19.1.1. 安装到OSX/Linux
先决条件
安装 neo4j-embedded
19.1.2. 安装到 Windows
先决条件
安装 neo4j-embedded
解决缺失DLL 文件的问题
19.2. Core API
19.2.1. 开始
创建一个数据库
用配置创建一个数据库
JPype JVM 配置
19.2.2. 事务
19.2.3. 节点
创建一个节点
通过Id找到一个节点
找到参考节点
移除一个节点
通过id移除一个节点
从一个节点上访问他的关系
获取并计算节点个数
19.2.4. 关系
创建一个关系
通过Id找到一个关系
移除一个关系
通过Id移除一个关系
关系的起点,终点和关系类型
获取所有的关系以及数量
19.2.5. 属性
设置属性值
获取属性值
移除属性
通过属性轮询
19.2.6. 路径
访问开始节点和结束节点
访问关系
通过完整的路径轮询
19.3. 索引
19.3.1. 索引管理
创建一个索引
接收一个预先存在的索引
移除索引
检查一个索引是否存在
19.3.2. 被索引的东西
增加节点或者关系到索引
移除索引的条目
19.3.3. 查询一个索引
直接轮循
查询
19.4. Cypher 查询
19.4.1. 查询并读取结果
基本查询
接收查询的结果
列出结果中的列
19.4.2. 参数化,并准备查询
参数化查询
准备查询
19.5. 遍历查询
19.5.1. 基本的遍历查询
跟随一个关系
在一个特定的方向跟随一个关系
跟随多个关系类型
19.5.2. 遍历查询结果
19.5.3. 唯一性
19.5.4. 顺序
19.5.5. 评估器 - 高级过滤器
部分 IV. 操作
第 20 章 安装和部署
20.1. 部署方案
20.1.1. 服务器模式
20.1.2. 嵌入模式
20.2. 系统要求
20.2.1. 中央处理器
20.2.2. 内存
20.2.3. 磁盘
20.2.4. 文件系统
20.2.5. 软件
20.2.6. JDK 版本
20.3. 安装
20.3.1. 嵌入模式安装
20.3.2. 服务器安装
20.4. 升级
20.4.1. 自动升级
20.4.2. 显性升级
20.5. 使用数据收集器
20.5.1. 技术信息
20.5.2. 如何关闭UDC功能
第 21 章 配置和调优
21.1. 介绍
21.1.1. 如何增加配置设置
21.2. 性能向导
21.2.1. 首先尝试
21.2.2. Neo4j 基础元素的生命周期
21.2.3. 配置Neo4j
磁盘, 内存和其他要点
写操作性能
二级缓存
21.3. 内核配置
21.4. Neo4j的缓存设置
21.4.1. 文件缓冲区
配置
21.4.2. 对象缓冲区
配置
GC耐高速缓存配置
堆内存使用
21.5. 逻辑日志
21.6. JVM设置
21.6.1. Configuring heap size and GC
21.7. 短字符串的压缩存储
21.8. 短数组的压缩存储
21.9. 内存I映射配置
21.9.1. Optimizing for traversal speed example
21.9.2. Batch insert example
21.10. Linux性能向导
21.10.1. Setup
21.10.2. Running the benchmark
21.10.3. Fixing the problem
21.11. Linux特有的注意事项
21.11.1. File system tuning for high IO
21.11.2. Setting the number of open files
第 22 章 高可用性模式
22.1. 架构
22.2. 安装和配置
22.2.1. Small
22.2.2. Medium
22.2.3. Large
22.2.4. Installation Notes
22.3. How Neo4j HA operates
22.4. Upgrading a Neo4j HA Cluster
22.4.1. Overview
22.4.2. Step 1: On each slave perform the upgrade
22.4.3. Step 2: Upgrade the master, complete the p
22.5. HA安装向导
22.5.1. Background
Download and unpack Neoj4 Enterprise
22.5.2. Setup and start the Coordinator cluster
22.5.3. Start the Neo4j Servers in HA mode
22.5.4. Start Neo4j Embedded in HA mode
22.6. 安装HAProxy作为一个负载均衡器
22.6.1. Installing HAProxy
22.6.2. Configuring HAProxy
22.6.3. Configuring separate sets for master and s
22.6.4. Cache-based sharding with HAProxy
第 23 章 备份
23.1. 嵌入数据库和独立数据库服务器
23.2. 在Java中进行在线备份
23.3. 高可用性模式
23.4. 恢复你的数据
第 24 章 安全
24.1. 安全访问Neo4j服务器
24.1.1. 加强端口和远程客户端连接请求的安全
24.1.2. 任意的代码执行
24.1.3. HTTPS支持
24.1.4. 服务端授权规则
加强服务端授权规则
使用通配符设置安全规则
24.1.5. 基于主机的脚本支持
24.1.6. 深度安全
24.1.7. 用一个代理重写URL规则
第 25 章 监视服务器
25.1. 调整远程JMX访问Neo4j的服务器
25.2. 如何使用JMX和JConsole连接到一个Neo4j实例
25.3. 如何编程连接到JMX监视器
部分 V. 工具集
第 26 章 基于Web的Neo4j图数据库管理工具
26.1. 仪表盘选项
26.1.1. 实体图
26.1.2. 监视器状态
第 27 章 Neo4j命令行
27.1. 启动 shell
27.1.1. 使能Shell服务器
27.1.2. 连接到Shell服务器
27.1.3. 把shell指向一个路径
27.1.4. 只读模式
27.1.5. 运行一个命令然后退出
27.2. 传递选项和参数
27.3. 枚举选项
27.4. 过滤器
27.5. 节点标题标签
27.6. 如何使用私有命令
27.6.1. 当前节点/关系以及路径
27.6.2. 列出一个节点/关系的内容
27.6.3. 创建节点和关系
27.6.4. 设置,重命名和移除属性
27.6.5. 移除节点和关系
27.6.6. 环境变量
27.6.7. 执行 groovy/python 脚本
27.6.8. 遍历查询
27.6.9. 通过Cypher查询
27.6.10. 索引
27.6.11. 事务
27.7. 扩展Shell: 增加你自己的命令
27.8. 一个Shell会话范例
27.9. 黑客帝国范例
部分 VI. 社区
第 28 章 社区支持
第 29 章 促进Neo4j发展
A.1. neo4j
A.1.1. 名称
A.1.2. 语法
A.1.3. 描述
A.1.4. 命令
A.1.5. 用法 - Windows
A.1.6. 涉及到的配置文件
A.2. neo4j-shell
A.2.1. 名称
A.2.2. 语法
A.2.3. 描述
A.2.4. 远程选项
A.2.5. 本地选项
A.2.6. 范例
A.3. neo4j-backup
A.3.1. 名称
A.3.2. 语法
A.3.3. 描述
A.3.4. 备份类型
A.3.5. 数据源地址
A.3.6. 用法 - Windows
A.4. neo4j-coordinator
A.4.1. 名称
A.4.2. 语法
A.4.3. 描述
A.4.4. 命令
A.4.5. 涉及到的相关配置文件
A.5. neo4j-coordinator-shell
A.5.1. 名称
A.5.2. 语法
A.5.3. 描述
A.5.4. 选项
附录 B. 常见问题
目录 前言 I. 简介 1. Neo4j 的亮点 2. 图数据库概要 3. Neo4j 图数据库 II. 教程 4. 在 Java 应用中使用 Neo4j 5. Neo4j 远程客户端库 6. 遍历查询框架 7. 数据模型范例 8. 多语言支持 9. 在 Python 应用中使用 Neo4j 10. 扩展 Neo4j 服务器 III. 参考 11. 性能 12. 事务管理 13. 数据导入 14. 索引 15. Cypher 查询语言 16. 图形算法 17. Neo4j 服务器 18. REST API 19. 在 Python 中使用 Neo4j 嵌入模式 IV. 操作 20. 安装和部署 21. 配置和调优 22. 高可用性模式 23. 备份 24. 安全 25. 监视服务器 V. 工具集 26. 基于 Web 的 Neo4j 图数据库管理工具 27. Neo4j 命令行 VI. 社区 28. 社区支持 29. 促进 Neo4j 发展 A. 联机帮助页 A.1. neo4j A.2. neo4j-shell A.3. neo4j-backup A.4. neo4j-coordinator A.5. neo4j-coordinator-shell B. 常见问题 1
第 1 章 Neo4j 的亮点 作为一款强健的,可伸缩的高性能数据库,Neo4j 最适合完整的企业部署或者用于一个轻 量级项目中完整服务器的一个子集存在。 它包括如下几个显著特点: 完整的 ACID 支持 高可用性 轻易扩展到上亿级别的节点和关系 通过遍历工具高速检索数据 适当的 ACID 操作是保证数据一致性的基础。Neo4j 确保了在一个事务里面的多个操作同 时发生,保证数据一致性。不管是采用嵌入模式还是多服务器集群部署,都支持这一特性。更 多详细的介绍,请参考章节:transactions。 可靠的图型存储可以非常轻松的集成到任何一个应用中。随着我们开发的应用在运营中不 断发展,性能问题肯定会逐步凸显出来,而 Neo4j 不管应用如何变化,他只会受到计算机硬件 性能的影响,不受业务本身的约束。部署一个 neo4j 服务器便可以承载上亿级的节点和关系。 当然,当单节点无法承载我们的数据需求时,我们可以进行分布式集群部署,详细的细节,请 参考章节:ha。将图数据库用于存储关系复杂的数据是他最大的优势。通过 Neo4j 提供的遍历 工具,可以非常高效的进行数据检索,每秒可以达到上亿级的检索量。一个检索操作类似于 RDBMS 里面的连接(_join_)操作。 第 2 章 图数据库概要 这个章节包括一个对图数据模型的介绍以及将它与其他我们常见的数据持久化模型 的比较。 2.1. 什么是图数据库? 图数据库用图来存储数据,是最接近高性能的一种用于存储数据的数据结构方式之 一。让我们跟随下面的图表,用他们来解释图数据库相关概念。我们将跟随图表中箭头方 向来读懂图想表达的真正含义。 2.1.1. 一个图由无数的节点和关系组成 “一张图 – 数据记录在 → 节点 → 包括的 → 属性里面” 最简单的图是单节点的,一个记录,记录了一些属性。一个节点可以从单属性开始, 成长为成千上亿,虽然会有一点点麻烦。从某种意义上讲,将数据用关系连接起来分布到 不同节点上才是有意义的。 2
2.1.2. 关系将图各个部分组织起来 “节点 — 被组织 → 关系 — 可以有 → 属性” 关系可以将节点组织成任意的结构,允许一张图被组织成一个列表,一棵树,一张地 图,或者一个复杂的实体 – 这个实体本身也是由复杂的,关系高度关联的结构组成。 2.1.3. 用 Traversal 进行数据库查询 “一个 Traversal — 导航 → 一张图; 他 — 标示 → 路径 — 包含 → 节点” 一次 Traversal, 你可以理解为是你通过一种算法,从一些开始节点开始查询与其关联 的节点,比如你想找到 “我朋友喜欢但我不喜欢的那首音乐是什么呢?”,又或者 “如果断 电了,拿下服务器的服务会首影响?”等等问题。 3
2.1.4. 为节点和关系建立索引 “一个索引 — 映射到 → 属性 — 属于 → 节点或者关系” 经常,你想通过某一给定的属性值找到节点或者关系。比起通过遍历我们的图来书, 用索引将会更加高效。比如“找到用户名是 tony 的用户”。 4
2.1.5. Neo4j 是一个图数据库 “一个图数据库 — 管理 → 一张图 和与图相关的 → 索引” Neo4j 是一个有商业支持的开源图数据库。他被设计来用于拿下数据不断高速成长的 数据存储,用高效的图数据结构代替传统的表设计。用 Neo4j 工作,您的应用将得到图的 所有优越表现,以及您期望的高可靠性。 2.2. 比较各种数据库模型 图数据库通过在一张图上存储节点和关系来持久化我们的数据结构。比起其他持久化 数据模型如何呢?因为图是一种常规数据结构,让我们与其他的进行一下比较试试看。 2.2.1. 从图数据库转换成 RDBMS 将所有的数据用竖立的堆栈表示,并且保持他们直接的关系,你可以看到下面一张图。 一个 RDBMS 被优化用于聚合数据,而 Neo4j 擅长于高度关联的数据。 5
图 2.1. RDBMS 图 2.2. 用图实现RDBMS 模型 2.2.2. 从图数据库转换成 Key-Value 数据库 Key-Value 模型适合用于简单的数据或者列表。当数据之间不断交互关联时,你更需 要一张图模型。Neo4j 让你能惊醒制作简单的数据结构到复杂,互相连接的数据。 图 2.3. Key-Value 存储模型 K* 代表一个键,V* 代表一个值。请注意,某些键指向其他键以及普通值。 6
图 2.4. 用图实现 Key-Value 模型 2.2.3. 从图数据库转换成列数据库 列式(大表)数据库是 Key-Value 模型的升级,用 “”来允许行数据增加。如果存储 一张图,这个表将是分层的,关系也是非常明确的。 2.2.4. 从图数据库转换成文档型数据库 文档型数据库用文档进行层次划分,而自由的数据规划也很容易被表示成一颗树。成 长为一张图的话,文档之间的关联你需要更有代表性的数据结构来存储,而在 Neo4j 中, 这些关系是非常容易处理的。 图 2.5. 文档型数据库 D=文档, S=子文档, V=值, D2/S2 = 关联到(其他)文档的索引。 图 2.6. 从图数据库转换成文档型数据库 7
第 3 章 Neo4j 图数据库 这个章节将讲述 Neo4j 模型和行为的更多细节。 3.1. 节点 构成一张图的基本元素是节点和关系。在 Neo4j 中,节点和关系都可以包含属性。 节点经常被用于表示一些_实体_,但依赖关系也一样可以表示实体。 下面让我们认识一个最简单的节点,他只有一个属性,属性名是 name,属性值是 Marko: 3.2. 关系 节点之间的关系是图数据库很重要的一部分。通过关系可以找到很多关联的数据,比如节 点集合,关系集合以及他们的属性集合。 8
分享到:
收藏