Neo4j 简明教程
Neo4j - Index
Neo4j SQL 支持节点或关系属性上的索引以提升应用程序性能。我们可以在具有相同标签名称的所有节点上为属性创建索引。
Neo4j SQL supports Indexes on node or relationship properties to improve the performance of the application. We can create indexes on properties for all nodes, which have the same label name.
我们可以在 MATCH 或 WHERE 或 IN 运算符上使用这些索引列以提升 CQL 命令的执行。
We can use these indexed columns on MATCH or WHERE or IN operator to improve the execution of CQL command.
在本章中,我们将讨论如何 −
In this chapter, we will discuss how to −
-
Create an Index
-
Delete an Index
Creating an Index
Neo4j CQL 提供了“CREATE INDEX”命令在 Node 或 Relationship 属性上创建索引。
Neo4j CQL provides "CREATE INDEX" command to create indexes on Node or Relationship properties.
Syntax
以下是在 Neo4j 中创建索引的语法。
Following is the syntax to create an index in Neo4j.
CREATE INDEX ON:label (node)
Example
在继续执行示例之前,创建节点 Dhawan,如下所示。
Before proceeding with the example, create a node Dhawan as shown below.
CREATE (Dhawan:player{name: "shikar Dhawan", YOB: 1995, POB: "Delhi"})
以下是 Cypher 查询示例,在 Neo4j 中为节点 Dhawan 创建索引。
Following is a sample Cypher Query to create an index on the node Dhawan in Neo4j.
CREATE INDEX ON:player(Dhawan)
执行上述查询,执行以下步骤:
To execute the above query, carry out the following steps −
Step 1 − 打开 Neo4j 桌面应用程序并启动 Neo4j 服务器。使用 URL http://localhost:7474/ 打开 Neo4j 的内置浏览器应用程序,如下所示。
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown below.

Step 2 - 在美元提示符中复制并粘贴所需的查询,并按播放按钮(执行查询)突出显示在下面的屏幕截图中。
Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.

Deleting an Index
Neo4j CQL 提供了“DROP INDEX”命令来删除 Node 或 Relationshis 属性的现有索引。
Neo4j CQL provides a "DROP INDEX" command to drop an existing index of a Node or Relationshis property.
Syntax
以下是在 Neo4j 中创建索引的语法。
Following is the syntax to create an index in Neo4j.
DROP INDEX ON:label(node)
Example
以下是 Cypher 查询示例,在 Neo4j 中为名为“Dhawan”的节点创建索引。
Following is a sample Cypher Query to create an index on the node named “Dhawan” in Neo4j.
DROP INDEX ON:player(Dhawan)
执行上述查询,执行以下步骤:
To execute the above query, carry out the following steps −
Step 1 - 打开 Neo4j Desktop App 并启动 Neo4j Server。使用 URL http://localhost:7474/ 打开 Neo4j 的内置浏览器应用,如下面的屏幕截图所示。
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in the following screenshot.

Step 2 - 在美元提示符中复制并粘贴所需的查询,并按播放按钮(执行查询)突出显示在下面的屏幕截图中。
Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.
