我使用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 detailsget_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语句。
有人能帮我把这个拿出来吗?
谢谢!
发布于 2014-08-15 14:26:22
Point no 1:确保您的GraphDatabaseService URI上有一个尾随斜杠。没有它你可能会得到不正确的结果。
No.2:这里使用的是遗留索引。通过读取这清楚地知道您使用的是哪种类型的索引。
我认为你混淆了索引和索引条目。索引(在这个实例中可能称为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此页可能会帮助处理代码中的一些细节,因为它描述了这里需要的遗留索引函数。
https://stackoverflow.com/questions/25321604
复制相似问题