[英]Cannot view the nodes I created using py2neo using a cypher query in the browser
我正在使用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語句。
有人可以幫我這個忙嗎?
謝謝!
第一點 :確保GraphDatabaseService URI上有一個斜杠。 沒有它,您可能會得到不正確的結果。
第2點 :您在此處使用舊版索引 。 閱讀this可以清楚了解所使用的索引類型。
我認為您混合使用了索引和索引條目 。 索引 (在本例中可能稱為“ People
)指向一組條目,每個條目均由鍵值對標識。 在每個入口點,您可以引用一個或多個節點。 在此處閱讀更多有關舊索引的信息 。
您可能希望您的代碼看起來像這樣:
from py2neo import neo4j
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
# Create a "People" index if one doesn't already exist
people = graph_db.get_or_create_index(neo4j.Node, "People"):
# Create two people nodes if they don't already exist
kiran = people.get_or_create("name", "Kiran", {"name": "Kiran"})
teja = people.get_or_create("name", "Teja", {"name": "Teja"})
# Relate the two
brothers, = graph_db.create((kiran, "BROTHER", teja))
print kiran
print teja
print brothers
此頁面可能會幫助您處理代碼中的一些細節,因為它描述了您在此處需要的舊索引函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.