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.