创建具有相同标签但不同属性的关系

Creating Relationships with Same Label but Different Properties

我的目标是创建动态关系,并将时间戳存储为关系的 属性。因此,2 个节点可能有许多具有相同标签但不同 属性 值的关系。

我可以通过以下方式使用 Cypher 实现:

CREATE 
(s1:Node {name:'s1'}), 
(s2:Node{name:'s2'}), 
(s1)-[r1:CONNECTS_TO{from:456}]->(s2), 
(s1)-[r2:CONNECTS_TO{from:1234}]->(s2)

但是,我找不到使用 Py2neo 的相同方法。 我试过这个:

from py2neo import Graph, Node, Relationship

graph = Graph(password='neo4jneo4j')

s1 = Node('Node', name='s1')
s2 = Node('Node', name='s2')

aw = Relationship(s1, 'CONNECTS_TO', s2, from=456)
graph.create(aw)

aw2 = Relationship(s1, 'CONNECTS_TO', s2, from=1234)
graph.create(aw2)

上面的代码没有创建两个关系。相反,后一个更新前一个。

我如何使用 Py2neo 完成它?

谢谢!

py2neo NodeRelationship 对象不可能做到这一点。您必须使用 Cypher 来创建多个类似的关系。