简体   繁体   中英

How to find if a relationship of correct type and parameters exists in Neo4j using python neo4jrestclient

Is there a way using the python neo4jrestclient library to determine if two nodes are connected by a specific relationship? I can only provide properties and values as parameters (and not nodes or relationship types) in a call to the query method so after getting a result set, I need to iterate over it and check if the start, end and relationship type are all correct.

ridx = gdb.relationships.indexes['relationship_auto_index']
results = ridx.query('flag:true')
filtered = [r for r in results if r.type=='Link']
# .. code to check start and end

neo4jrestclient supports cypher as query language. So if you have some means of identifying the start and end node, eg index lookup, you can query directly:

START n = node:mynodes(key='someuuidperhaps'), m = node:mynodes(key='otheruuidperhaps')
MATCH n -[r:KNOWS]-m
WHERE r.flag = True
return r

You can match on the direction of the relationship, using -> or <- .

In addition to that, I'd recommend py2neo , which I consider to have the better API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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