//Connect to Titan through germlin console g = TitanFactory.open('conf/titan-cassandra-es.properties') g1 = g.traversal() //mgmt Start mgmt = g.openManagement() //Labels person = mgmt.makeVertexLabel('person').make() category = mgmt.makeVertexLabel('category').make() vote = mgmt.makeEdgeLabel('vote').multiplicity(MULTI).make() //Multiplicity //Indexes //user_id (int) user_id = mgmt.makePropertyKey('user_id').dataType(Integer.class).cardinality(Cardinality.SINGLE).make() user_id = mgmt.getPropertyKey('user_id') mgmt.buildIndex('byPersonUserIdUnique', Vertex.class).addKey(user_id).indexOnly(person).unique().buildCompositeIndex() mgmt.setConsistency(user_id, ConsistencyModifier.LOCK) //category_name (string) category_name = mgmt.makePropertyKey('category_name').dataType(String.class).cardinality(Cardinality.SINGLE).make() category_name = mgmt.getPropertyKey('category_name') mgmt.buildIndex('byCategoryNameUnique', Vertex.class).addKey(category_name = mgmt.getPropertyKey('category_name')).indexOnly(category).unique().buildCompositeIndex() mgmt.setConsistency(category_name, ConsistencyModifier.LOCK) //votes edge votes = mgmt.makePropertyKey('votes').dataType(String.class).cardinality(Cardinality.SET).make() votes = mgmt.getPropertyKey('votes') mgmt.buildIndex('byEdgeVoteUnique', Vertex.class).addKey(votes).unique().buildCompositeIndex() mgmt.setConsistency(votes, ConsistencyModifier.LOCK) //mgmt end mgmt.commit() //Input Data //Vertices //People vp1 = g.addVertex(T.label, "person", "user_id", 1, "name", "Jared", "age", 29) vp2 = g.addVertex(T.label, "person", "user_id", 2, "name", "Brad", "age", 3000) //categories vc3 = g.addVertex(T.label, "category", "category_name", "dog") vc4 = g.addVertex(T.label, "category", "category_name", "cat") vc5 = g.addVertex(T.label, "category", "category_name", "fur") //votes //dog vp1.addEdge("vote", vc3, "votes", "'cat','fur'") vp2.addEdge("vote", vc3, "votes", "'fur','cat'") //cat vp1.addEdge("vote", vc4, "votes", "'fur','dog'") vp2.addEdge("vote", vc4, "votes", "'dog','fur'") //fur vp1.addEdge("vote", vc5, "votes", "'dog','cat'") vp2.addEdge("vote", vc5, "votes", "'cat','dog'")