문제

In Titan, I create an index using:

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

How can I do this in Neo4j using the Java API?

도움이 되었습니까?

해결책

In Cypher you would create a label based constraint on the label :Person and the property name like this.

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

In the Java API it is

try (Transaction tx = db.beginTx()) {      
  db.schema().constraintFor(DynamicLabel.label("Person")).assertPropertyIsUnique("name").create();
  tx.success();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top