Neo4j RedisGraph-展开查询的批处理
我想用Python API在Redistrations中执行一批查询,以便加快创建大知识图 在Neo4J中,Neo4J Python API可以使用UNWIND命令,并允许并行化查询。在这个代码片段中,您可以看到Python API如何支持展开—Neo4j RedisGraph-展开查询的批处理,neo4j,redis,cypher,redis-py,redisgraph,Neo4j,Redis,Cypher,Redis Py,Redisgraph,我想用Python API在Redistrations中执行一批查询,以便加快创建大知识图 在Neo4J中,Neo4J Python API可以使用UNWIND命令,并允许并行化查询。在这个代码片段中,您可以看到Python API如何支持展开—run方法将batch作为参数批处理是字典列表。每个字典都有头id、尾id和属性作为键 with session.begin_transaction() as tx: # In this transaction relationships are in
run
方法将batch
作为参数<代码>批处理是字典列表。每个字典都有头id
、尾id
和属性
作为键
with session.begin_transaction() as tx: # In this transaction relationships are inserted in the database
cypher_query = 'UNWIND $batch as row ' \
'MATCH (head:Node) WHERE head.id = row.head_id ' \
'MATCH (tail:Node) WHERE tail.id = row.tail_id ' \
'CREATE (head)-[rel:RELATIONSHIP]->(tail) ' \
'SET rel += row.properties'
tx.run(cypher_query, batch=batch)
在RedisGraph中,也可以使用“展开”(因为它是一个密码命令)。但是,我不知道如何在Python API中传递批处理:
cypher_query = 'UNWIND $batch as row ' \
'MATCH (head:Node) WHERE head.id = row.head_id ' \
'MATCH (tail:Node) WHERE tail.id = row.tail_id ' \
'CREATE (head)-[rel:RELATIONSHIP]->(tail) ' \
'SET rel += row.properties'
r = redis.StrictRedis()
r.execute_command('GRAPH.QUERY', graph_name, cypher_query) #No batch can be passed!!
你知道解决办法吗?谢谢。redisgraph py自述文件显示了如何通过其
查询()方法传递参数的示例:
如果您确实需要使用execute_command()
,您可以查看一下。这里是RedisLabs开发团队的答案:
github.com/RedisGraph/RedisGraph/issues/1293
目前,该功能不受支持,但将在将来推出。谢谢您的回答。我认为redis_graph.query(query,params)并没有真正实现我想要的东西。在我在问题中发布的截图中,batch是一个字典列表,然后通过UNWIND命令将其取消。query()似乎不支持这一点。
...
params = {'purpose':"pleasure"}
query = """MATCH (p:person)-[v:visited {purpose:$purpose}]->(c:country)
RETURN p.name, p.age, v.purpose, c.name"""
result = redis_graph.query(query, params)
...