将重复的嵌套JSON结构转换为CYPHER语句以构建血统

时间:2019-06-26 15:11:10

标签: json neo4j cypher neo4j-apoc

想要将重复的JSON对象转换为cypher语句,该语句将创建具有4个唯一节点,3个关系的图形,如下面的示例json中所定义。n相反,我得到了3对节点,每对都有一个重复的节点另一对。

我的密码声明

with "/var/lib/neo4j/import/FULL_METADATA_V3.json" as file

CALL apoc.load.json(file) YIELD value

UNWIND value.lineage AS lineage

CALL apoc.create.node(lineage.source.labels, lineage.source.attributes) yield node as src

CALL apoc.create.node(lineage.target.labels, lineage.target.attributes) yield node as trg

call apoc.create.relationship(src, lineage.action.relationship, lineage.action.attributes, trg) yield rel

return src, trg:

{"lineage" : [{

"source": {

"labels":["Node","Application"],

"attributes": {

"Name":"AppStep1",

"Type":"process"}

},

"action": {

"relationship": "OPERATION",

"attributes": {

"RunStep": 1,

"WorkflowOwner": "user1"}

},

"target": {

"labels":["Node","Application"],

"attributes": {

"Name":"AppStep2",

"Type":"process"}

}

}, {

"source": {

"labels":["Node","Application"],

"attributes": {

"Name":"AppStep2",

"Type":"process"}

},

"action": {

"relationship": "OPERATION",

"attributes": {

"RunStep": 2,

"WorkflowOwner": "user1"}

},

"target": {

"labels":["Node","Application"],

"attributes": {

"Name":"AppStep3",

"Type":"process"}

}

},{

"source": {

"labels":["Node","Application"],

"attributes": {

"Name":"AppStep3",

"Type":"process"}

},

"action": {

"relationship": "OPERATION",

"attributes": {

"RunStep": 3,

"WorkflowOwner": "user1"}

},

"target": {

"labels":["Node","Application"],

"attributes": {

"Name":"AppStep4",

"Type":"process"}

}

}

]

}

所需的输出是4个节点和3个关系,但是目前我正在获得3对节点,有关如何完成操作的任何建议?

0 个答案:

没有答案