Indices
We have added a property country
to every node labeled as City
. We can search for cities belonging to a country as well. Searching without indexes is inefficient, and hence, it's a good practice to add an index for properties which we anticipate the nodes will be searched by. Let's see how this is done using an example as shown:
neo4j-sh (?)$ CREATE INDEX ON :City(country);
The output is as follows:
+-------------------+ | No data returned. | +-------------------+ Indexes added: 1
Creating an index returns Indexes added: 1
. However, at this point, an index may not have been added—but will be created. In our database, an index would already have been created. In larger datasets, the indexing will take time.
The index we have just created is called schema index.
Note
Whenever we send Neo4j a Cypher query for execution, Neo4j will try reducing the queried graph to a small subgraph, and then try comparing which nodes have properties:value
queried. In larger databases, the subgraph itself might...