获取模型之间的所有关系,包括节点数据

问题描述 投票:0回答:1

我有这个节点和关系,但我有一个关于 fromto 节点信息

的问题

我有这3笔交易

  • 从:111,到:222 -> 金额:$10000
  • 从:222,到:333 -> 金额:$2000
  • 从:222,到:444 -> 金额:$4000

有了这个查询(不确定是否可以)

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"
}

如何使用 startend 键获取 contact_id 并将其添加到结果中?

neo4j cypher
1个回答
0
投票

开始和结束键指的是 Neo4j 内部节点标识符,不应在 Neo4j 外部使用,因为它们会随着时间的推移而改变。

您的查询本身不应该需要使用这些;以下查询应该有效:

MATCH (c:Contact {contact_id: '111'})-[t:TRANSACTION*1..3]-()
RETURN c, t

不需要使用distinct(t),因为 Neo4j 不会在单个路径中两次使用相同的关系。

© www.soinside.com 2019 - 2024. All rights reserved.