Search code examples
indexingneo4jcypheruniquerelationships

Adding Automate Unique Indexes on Relationships (CYPHER, Neo4j)


I have a set of relationships in Neo4j on which I want to add unique indexes in an automated way, does anybody know how that can be done automatically?

Also would be nice to have an example on how to generate automated unique values to associate with new entities in a query. Thanks.


Solution

    1. Neo4j has "automatic" indexes for nodes, but not relationships. You can create legacy indexes for relationships, but they are no longer the preferred way to index, and relationships will not be added automatically to such an index. You are responsible for "manually" adding nodes/relationships to legacy indexes. In neo4j 3.0, there are APOC procedures for manual indexes that you can call from Cypher, which makes this more convenient, but it is still not "automatic".

      NOTE: APOC procedures must be installed on the neo4j server before you can use them.

    2. In neo4j 3.0, your Cypher code can now use APOC procedures to get UUIDs. For example, to get a single UUID:

      CALL apoc.create.uuid YIELD uuid