我正在尝试在Titan图数据库(Titan1.0.0)中创建顶点和边..
gremlin> graph = TitanFactory.open('titan-1.0.0-hadoop1/conf/titan-cassandra-es.properties')
gremlin> t1 = graph.addVertex(label, "Testbed", "Name", "testbed1","Status","A","TId",101)
==>v[1228816568]
gremlin> r2= graph.addVertex(label, "Router", "RStatus","F","RId",1002, "TId", 101)
==>v[3686424680]
gremlin> t1.addEdge("tbConRtr", r2)
==>e[kblqtz-kblsxk-d6vp-1oysvhk][1228816568-tbConRtr->3686424680]
问题:
1)为什么这里返回的顶点数不是序列而是一些随机数?对于addEdge
步骤,它也会使用一些随机值(kblqtz-kblsxk-d6vp-1oysvhk
)
e[kblqtz-kblsxk-d6vp-1oysvhk][1228816568-tbConRtr->3686424680]
2)我希望我的TId
值应该是唯一的
我尝试了以下内容并获得了错误消息:
gremlin> mgmt.buildIndex("TId",Vertex.class).addKey(TId).unique().buildCompositeIndex();
No such property: TId for class: groovysh_evaluate
如何在Titan数据库中创建唯一的属性值?
请帮我解决这个问题。
答案 0 :(得分:3)
错误No such property: TId
表示您正在尝试使用尚未初始化的变量TId
。您应该在尝试索引之前定义顶点属性
gremlin> graph = TitanFactory.open('conf/titan-cassandra-es.properties')
==>standardtitangraph[cassandrathrift:[127.0.0.1]]
gremlin> mgmt = graph.openManagement()
==>com.thinkaurelius.titan.graphdb.database.management.ManagementSystem@4b97b3d2
gremlin> TId = mgmt.makePropertyKey("TId").dataType(Integer.class).cardinality(Cardinality.SINGLE).make()
==>TId
gremlin> mgmt.buildIndex("TId",Vertex.class).addKey(TId).unique().buildCompositeIndex()
==>TId
gremlin> mgmt.commit()
==>null
gremlin> t1 = graph.addVertex(label, "Testbed", "Name", "testbed1","Status","A","TId",101)
==>v[4200]
gremlin> r2= graph.addVertex(label, "Router", "RStatus","F","RId",1002, "TId", 101)
Adding this property for key [TId] and value [101] violates a uniqueness constraint [TId]
请参阅schema and data modeling以及indexing for better performance上的Titan文档。