【问题标题】:How would I create this index in Neo4j?我将如何在 Neo4j 中创建这个索引?
【发布时间】:2014-03-15 00:02:28
【问题描述】:

在 Titan 中,我使用以下方法创建索引:

graph.makeKey("name").dataType(String.class).indexed(Vertex.class).indexed(Edge.class).unique().make();

如何在 Neo4j 中使用 Java API 做到这一点?

【问题讨论】:

    标签: java neo4j graph-databases titan


    【解决方案1】:

    在 Cypher 中,您可以像这样在标签 :Person 和属性 name 上创建一个基于标签的约束。

    CREATE CONSTRAINT ON (p:Person) ASSERT p.name IS UNIQUE;
    

    在 Java API 中是

    try (Transaction tx = db.beginTx()) {      
      db.schema().constraintFor(DynamicLabel.label("Person")).assertPropertyIsUnique("name").create();
      tx.success();
    }
    

    【讨论】:

    • 我正在使用 Neo4j 的 Blueprints 实现,而 GraphDatabaseService 没有 schema() 方法,是否有 Neo4j2 的 Blueprints 实现?还是我需要做其他事情来检索Schema
    猜你喜欢
    • 2015-02-10
    • 1970-01-01
    • 2013-05-10
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多