Cassandra 灯泡:创造;在;及;“出去”;TitanDB中两个顶点之间的边

Cassandra 灯泡:创造;在;及;“出去”;TitanDB中两个顶点之间的边,cassandra,titan,bulbs,Cassandra,Titan,Bulbs,我正在使用Titan GraphDB+Cassandra。我正在启动Titan,如下所示 cd titan-cassandra-0.3.1 bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties 我有一个雷克斯特外壳,可以用来和上面的泰坦+卡桑德拉通信 cd rexster-console-2.3.0 bin/rexster-console.sh 我想从我的python程序中编

我正在使用Titan GraphDB+Cassandra。我正在启动Titan,如下所示

cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties
我有一个雷克斯特外壳,可以用来和上面的泰坦+卡桑德拉通信

cd rexster-console-2.3.0
bin/rexster-console.sh
我想从我的python程序中编程Titan Graph DB。我正在为此使用Bulls包

 from bulbs.titan import Graph
   g = Graph()


   vertex1  = g.vertices.get_or_create('dpid',dpid_str,{'state':'active','dpid':dpid_str,'type':'switch'}))
   vertex2  = g.vertices.get_or_create('desc',desc,{'desc':desc,'port_id':port_id,'state':state,'port_state':port_state,'number':number,'type':'port'}))
通过这些示例,我了解了如何在顶点之间创建边,如下所示

 g.edges.create(vertex1,"out",vertex2)
但是假设我的程序中没有对顶点的引用

我想用它的键“dpid”检索vertex1,然后 我想用它的键“desc”检索vertex2


然后使用检索到的值创建边。如何执行此操作?

要通过索引属性(与其数据库ID相反)检索顶点,可以使用内置索引方法之一:

>>> # returns an iterator (can return more than 1)
>>> vertices = g.vertices.index.lookup("dpid", dpid_str)   
>>> vertex1 = vertices.next()

>>> # returns 1 vertex or None (errors if more than 1)
>>> vertex2 = g.vertices.index.get_unique( "dpid", dpid_str)  
要创建边,只需执行以下操作

>>> g.edges.create(vertex1, "out", vertex2)
注意:不需要将边标记为“out”(“out”由边从顶点1向外和从顶点2向内的方向表示)。您应该考虑使用更具描述性的标签。

Rexter索引文档:

index.lookup()

index.get_unique()

可能存在的副本