【发布时间】:2014-08-15 05:22:09
【问题描述】:
我正在使用 py2neo 创建节点,如下所示:
from py2neo import neo4j
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data")
print graph_db.neo4j_version
graph_db.clear()
if not graph_db.get_index(neo4j.Node, "Kiran"):
from py2neo import node,rel
trial = graph_db.create(
node(name="Kiran"),
node(name="teja"),
rel(0, "Brother", 1),
)
#else:
details = graph_db.get_index(neo4j.Node, "Kiran")
print details
get_index 会返回一些数据,例如
Index(Node, u'http://localhost:7474/db/data/index/node/Kiran')
但是当我在浏览器上搜索节点时,它什么也没返回... 我在这里做错了吗?
我也在尝试发布一些网络信息如下:
from py2neo import neo4j
from py2neo import node,rel
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data")
def nodepublish(dpid, port, mac):
if graph_db.get_index( neo4j.Node, dpid ) == None:
create = graph_db.create({"DPID": dpid})
print "switch "+str(dpid)+" added to graph"
if graph_db.get_index( neo4j.Node, mac ) == None:
query = neo4j.CypherQuery(graph_db, "MATCH (sw) WHERE sw.DPID = "+str(dpid)+" CREATE (nd {MAC: "+str(mac)+"}) CREATE (sw)-[:connected {PORT: "+str(port)+"}]->(nd)")
print "node "+str(mac)+" added to graph"
当我像
一样调用 nodepublish() 函数时nodepublish(1,1,"aa:aa:aa:aa:aa:aa")
它每次都使用 dpid:1 创建一个新节点,而不是在 get_index 不返回 None 时跳过 if 语句。
有人可以帮我解决这个问题吗?
谢谢!
【问题讨论】:
标签: python neo4j cypher py2neo