繁体   English   中英

无法在浏览器中使用密码查询查看我使用py2neo创建的节点

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM