JanusGraph教程
1、创建Label
import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphFactory; import org.janusgraph.core.PropertyKey; import org.janusgraph.core.VertexLabel; import org.janusgraph.core.schema.JanusGraphManagement; import org.janusgraph.core.schema.SchemaStatus; import org.janusgraph.graphdb.database.management.ManagementSystem; public class Test { public static void main(String[] args) throws InterruptedException { JanusGraph graph = JanusGraphFactory.open("conf/janusgraph-cassandra-es.properties"); JanusGraphManagement mgmt = graph.openManagement(); //创建顶点Label VertexLabel luser = mgmt.makeVertexLabel("USER").make(); VertexLabel lphone = mgmt.makeVertexLabel("PHONE").make(); //创建边Label mgmt.makeEdgeLabel("USER_PHONE").make(); //创建属性 PropertyKey pUid = mgmt.makePropertyKey("uid").dataType(String.class).make(); PropertyKey pName = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey pAge = mgmt.makePropertyKey("age").dataType(Integer.class).make(); PropertyKey pPhone = mgmt.makePropertyKey("phone").dataType(String.class).make(); //创建索引 String uidIndex = "uidIndex"; mgmt.buildIndex(uidIndex, Vertex.class) .addKey(pUid) .indexOnly(luser) .unique() .buildCompositeIndex(); mgmt.commit(); //注册索引 ManagementSystem .awaitGraphIndexStatus(graph, uidIndex) .status(SchemaStatus.REGISTERED) .call(); //等待索引ok ManagementSystem.awaitGraphIndexStatus(graph, uidIndex).status(SchemaStatus.ENABLED).call(); graph.close(); } }
欢迎加:知识图谱QQ交流群:829449428