简体   繁体   English

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

[英]Cannot view the nodes I created using py2neo using a cypher query in the browser

I am creating nodes using py2neo as follows: 我正在使用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

the get_index returns me some data like get_index返回一些数据,例如

Index(Node, u'http://localhost:7474/db/data/index/node/Kiran')

but when I search for the node on the browser, it returns me nothing... am I doing something wrong here? 但是当我在浏览器上搜索节点时,它什么也没有返回……我在这里做错了吗?

also I am trying to publish some network information as follows : 我也试图发布一些网络信息,如下所示:

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"

When I call the nodepublish() function like 当我像这样调用nodepublish()函数时

nodepublish(1,1,"aa:aa:aa:aa:aa:aa")

It creates a new node with dpid:1 every time instead of skipping the if statement once the get_index doesn't return None. 每次使用dpid:1创建一个新节点,而不是在get_index不返回None时跳过if语句。

can someone help me out with this please? 有人可以帮我这个忙吗?

Thanks! 谢谢!

Point no 1 : make sure you have a trailing slash on your GraphDatabaseService URI. 第一点 :确保GraphDatabaseService URI上有一个斜杠。 You may get incorrect results without it. 没有它,您可能会得到不正确的结果。

Point no 2 : you are using legacy indexes here. 第2点 :您在此处使用旧版索引 Be clear about which type of index you are using by reading this . 阅读this可以清楚了解所使用的索引类型。

I think you have mixed up indexes and index entries . 我认为您混合使用了索引索引条目 An index (perhaps called People in this instance) points to a set of entries, each identified by a key-value pair. 索引 (在本例中可能称为“ People )指向一组条目,每个条目均由键值对标识。 At each entry point, you may reference one or more nodes. 在每个入口点,您可以引用一个或多个节点。 Read more on legacy indexes here . 此处阅读更多有关旧索引的信息

You probably want your code to look more like this: 您可能希望您的代码看起来像这样:

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

This page might help with some of the details in the code as it describes the legacy index functions that you need here. 此页面可能会帮助您处理代码中的一些细节,因为它描述了您在此处需要的旧索引函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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