我有这个节点和关系,但我有一个关于 from 和 to 节点信息
的问题我有这3笔交易
有了这个查询(不确定是否可以)
MATCH path = (:Contact {contact_id: '111'})-[t:TRANSACTION*1..3]-()
With relationships(path) as relations
unwind relations as u_relations
With distinct(u_relations) as distinct_relations
return distinct_relations
我得到了我需要的信息,但我不知道如何添加每笔交易的contact_id,结果是
{
"identity": 0,
"start": 0,
"end": 1,
"type": "TRANSACTION",
"properties": {
"date": "2023-08-03T17:08:34-03:00",
"amount": 10000.0
},
"elementId": "0",
"startNodeElementId": "0",
"endNodeElementId": "1"
}
{
"identity": 1,
"start": 1,
"end": 5,
"type": "TRANSACTION",
"properties": {
"date": "2023-08-03T17:08:34-03:00",
"amount": 2000.0
},
"elementId": "1",
"startNodeElementId": "1",
"endNodeElementId": "5"
}
{
"identity": 2,
"start": 1,
"end": 6,
"type": "TRANSACTION",
"properties": {
"date": "2023-08-03T17:08:35-03:00",
"amount": 4000.0
},
"elementId": "2",
"startNodeElementId": "1",
"endNodeElementId": "6"
}
如何使用 start 和 end 键获取 contact_id 并将其添加到结果中?
开始和结束键指的是 Neo4j 内部节点标识符,不应在 Neo4j 外部使用,因为它们会随着时间的推移而改变。
您的查询本身不应该需要使用这些;以下查询应该有效:
MATCH (c:Contact {contact_id: '111'})-[t:TRANSACTION*1..3]-()
RETURN c, t
不需要使用distinct(t),因为 Neo4j 不会在单个路径中两次使用相同的关系。