Neo4j 简明教程
Neo4j - Building Blocks
Neo4j 图形数据库具有以下构件 −
Neo4j Graph Database has the following building blocks −
-
Nodes
-
Properties
-
Relationships
-
Labels
-
Data Browser
Node
节点是一个图的基本单元。它包含具有键值对的属性,如下图所示。
Node is a fundamental unit of a Graph. It contains properties with key-value pairs as shown in the following image.

在此,节点名称 =“Employee”,它包含一系列属性作为键值对。
Here, Node Name = "Employee" and it contains a set of properties as key-value pairs.
Properties
属性是键值对,用来描述图形节点和关系。
Property is a key-value pair to describe Graph Nodes and Relationships.
Key = Value
其中键是一个字符串,值可以使用任何 Neo4j 数据类型表示。
Where Key is a String and Value may be represented using any Neo4j Data types.
Relationships
关系是图形数据库的另一个主要构建块。它将两个节点连接起来,如下图所示。
Relationships are another major building block of a Graph Database. It connects two nodes as depicted in the following figure.

这里,Emp 和 Dept 是两个不同的节点。“WORKS_FOR”是 Emp 和 Dept 节点之间的关系。
Here, Emp and Dept are two different nodes. "WORKS_FOR" is a relationship between Emp and Dept nodes.
它表示,从 Emp 到 Dept 的箭头标记描述了 -
As it denotes, the arrow mark from Emp to Dept, this relationship describes −
Emp WORKS_FOR Dept
每个关系包含一个起始节点和一个结束节点。
Each relationship contains one start node and one end node.
在这里,“Emp”是一个起始节点,“Dept”是一个结束节点。
Here, "Emp" is a start node, and "Dept" is an end node.
由于该关系箭头标记表示从“Emp”节点到“Dept”节点的关系,因此该关系被称为“Dept”节点的“流入关系”和“Emp”节点的“流出关系”。
As this relationship arrow mark represents a relationship from "Emp" node to "Dept" node, this relationship is known as an "Incoming Relationship" to "Dept" Node and "Outgoing Relationship" to "Emp" node.
与节点一样,关系也可以包含属性作为键值对。
Like nodes, relationships also can contain properties as key-value pairs.

在这里,“WORKS_FOR”关系具有一个属性作为键值对。
Here, "WORKS_FOR" relationship has one property as key-value pair.
Id = 123
它表示该关系的 ID。
It represents an Id of this relationship.
Labels
标签为一组节点或关系关联一个通用名称。一个节点或关系可以包含一个或多个标签。我们可以为现有节点或关系创建新标签。我们可以从现有节点或关系中移除现有的标签。
Label associates a common name to a set of nodes or relationships. A node or relationship can contain one or more labels. We can create new labels to existing nodes or relationships. We can remove the existing labels from the existing nodes or relationships.
从上一个图表中,我们可以观察到有 2 个节点。
From the previous diagram, we can observe that there are two nodes.
左侧节点具有标签:“Emp”,右侧节点具有标签:“Dept”。
Left side node has a Label: "Emp" and the right side node has a Label: "Dept".
这两个节点之间的关系也具有标签:“WORKS_FOR”。
Relationship between those two nodes also has a Label: "WORKS_FOR".
Note − Neo4j 将数据存储在节点或关系的属性中。
Note − Neo4j stores data in Properties of Nodes or Relationships.
Neo4j Data Browser
一旦我们安装了 Neo4j,我们就可以使用以下 URL 访问 Neo4j 数据浏览器
Once we install Neo4j, we can access Neo4j Data Browser using the following URL
http://localhost:7474/browser/

Neo4j 数据浏览器用于执行 CQL 命令和查看输出。
Neo4j Data Browser is used to execute CQL commands and view the output.
在这里,我们需要在美元提示符下执行所有 CQL 命令: "$"
Here, we need to execute all CQL commands at dollar prompt: "$"
在美元符号后键入命令,然后单击“执行”按钮来运行你的命令。
Type commands after the dollar symbol and click the "Execute" button to run your commands.
它与 Neo4j 数据库服务器交互,检索并将结果显示在美元提示符的正下方。
It interacts with Neo4j Database Server, retrieves and displays the results just below the dollar prompt.
使用“VI 视图”按钮以图表格式查看结果。上图显示了“UI 视图”格式下的结果。
Use "VI View" button to view the results in diagrams format. The above diagram shows results in "UI View" format.
使用“网格视图”按钮以网格视图形式查看结果。下图显示了以“网格视图”格式显示的相同结果。
Use "Grid View" button to view the results in Grid View. The following diagram shows the same results in "Grid View" format.

当我们使用“网格视图”来查看查询结果时,我们可以将其导出到两种不同格式的文件中。
When we use "Grid View" to view our Query results, we can export them into a file in two different formats.