在关系上添加自动唯一索引(CYPHER,Neo4j)

时间:2021-09-16 14:47:24

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?

我在Neo4j中有一组关系,我希望以自动方式添加唯一索引,是否有人知道如何自动完成?

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

如果有一个关于如何生成自动唯一值以与查询中的新实体相关联的示例,也会很高兴。谢谢。

2 个解决方案

#1


2  

  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".

    Neo4j具有节点的“自动”索引,但不具有关系。您可以为关系创建旧索引,但它们不再是索引的首选方式,并且关系不会自动添加到此类索引中。您负责“手动”向遗留索引添加节点/关系。在neo4j 3.0中,您可以从Cypher调用手动索引的APOC过程,这使得这更方便,但它仍然不是“自动”的。

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

    注意:必须先在neo4j服务器上安装APOC过程,然后才能使用它们。

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

    在neo4j 3.0中,您的Cypher代码现在可以使用APOC过程来获取UUID。例如,要获取单个UUID:

    CALL apoc.create.uuid YIELD uuid
    

#2


-1  

It seems like at present, CONSTRAINTs, and therefore unique indexing, can only be applied on nodes. I don't know if there is a plan to extend this feature to relationships.

看起来目前,CONSTRAINTs和独特的索引只能应用于节点。我不知道是否有计划将此功能扩展到关系。

#1


2  

  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".

    Neo4j具有节点的“自动”索引,但不具有关系。您可以为关系创建旧索引,但它们不再是索引的首选方式,并且关系不会自动添加到此类索引中。您负责“手动”向遗留索引添加节点/关系。在neo4j 3.0中,您可以从Cypher调用手动索引的APOC过程,这使得这更方便,但它仍然不是“自动”的。

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

    注意:必须先在neo4j服务器上安装APOC过程,然后才能使用它们。

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

    在neo4j 3.0中,您的Cypher代码现在可以使用APOC过程来获取UUID。例如,要获取单个UUID:

    CALL apoc.create.uuid YIELD uuid
    

#2


-1  

It seems like at present, CONSTRAINTs, and therefore unique indexing, can only be applied on nodes. I don't know if there is a plan to extend this feature to relationships.

看起来目前,CONSTRAINTs和独特的索引只能应用于节点。我不知道是否有计划将此功能扩展到关系。