Neo4j CQL - Index



Neo4j SQL supports Indexes on Node or Relationships properties to improve the performance of the application.

We can create indexes on properties for all nodes which have same label name.

We can use these indexed columns on MATCH or WHERE or IN operator to improve the execution of CQL Command.

Neo4J Index operations

  • Create Index
  • Drop Index

We will discuss these operations with examples in this chapter.

Create Neo4j Index

Neo4j CQL has provided "CREATE INDEX" command to create indexes on NODE's or Relationship's properties.

Create Index syntax:

CREATE INDEX ON :<label_name> (<property_name>)

NOTE:-

The colon(:) operator is used to refer a Node or a Relationship label name.

The above syntax describes that it creates a new index on <property_name> of <label_name> of a Node or a Relationship.

Example -

This example demonstrates how to Create INDEX on number property of a CreditCard Node.

Step 1 - Type the below command on Data Browser

CREATE INDEX ON :Customer (name)
Neo4j CQL Tutorial

Step 2 - Click on "Execute" button and observe the results.

Neo4j CQL Tutorial

It shows that one new Index is added to the Neo4j Database

Drop Neo4j Index

Neo4j CQL has provided "DROP INDEX" command to drop an existing index of a NODE's or Relationship's property.

Drop Index syntax:

DROP INDEX ON :<label_name> (<property_name>)

NOTE:-

The colon(:) operator is used to refer a Node or a Relationship label name.

The above syntax describes that it drops an existing index created on <property_name> of <label_name> of a Node or a Relationship.

Example -

This example demonstrates how to drop an INDEX on number property of a CreditCard Node.

Steps to follow:

Step 1 - Type the below command on Data Browser

DROP INDEX ON :Customer (name)
Neo4j CQL Tutorial

Step 2 - Click on "Execute" button and observe the results.

Neo4j CQL Tutorial

It shows that one Index is dropped from the Neo4j Database

Advertisements