如何将嵌套列表插入到具有直接关系的neo4j(cypher查询语言)中

如何将嵌套列表插入到具有直接关系的neo4j(cypher查询语言)中,neo4j,cypher,Neo4j,Cypher,我想通过cypher查询语言在neo4j4.1.1中插入一个多级列表 我要插入的数据是以json格式返回的报告列表。属性之一是报告背后的模型。我希望为列表中的每个报告创建一个节点+为给定报告中的每个模型创建一个节点,并在报告和模型(在报告中给出)之间添加一个关系。这将是一次每日数据刷新,因此如果neo4j数据库中不存在新的报告节点,我希望创建新的报告节点;如果报告已经存在,我希望在我们有新信息时覆盖数据 示例数据: [ { "name": "

我想通过cypher查询语言在neo4j4.1.1中插入一个多级列表

我要插入的数据是以json格式返回的报告列表。属性之一是报告背后的模型。我希望为列表中的每个报告创建一个节点+为给定报告中的每个模型创建一个节点,并在报告和模型(在报告中给出)之间添加一个关系。这将是一次每日数据刷新,因此如果neo4j数据库中不存在新的报告节点,我希望创建新的报告节点;如果报告已经存在,我希望在我们有新信息时覆盖数据

示例数据:

[
    {
        "name": "Report 1",
        "description": "Report Description",
        "createdBy": "TRAINING1",
        "id": "04CA095985D9A838E10000000A4E740E",
        "created": "2020-02-14T14:27:56.371Z",
        "changed": "2020-02-14T14:27:56.371Z",
        "isTemplate": false,
        "isSample": false,
        "models": [
            {
                "description": "Model 1",
                "id": "id of the model",
                "isPlanning": true
            },
            {
                "description": "Model 2",
                "id": "id of the model",
                "isPlanning": true
            },
            {
                "description": "Model 3",
                "id": "id of the model",
                "isPlanning": true
            },
          
        ],
        "changedBy": "TRAINING1",
        "openURL": "URL of the report"
    },
     {
        "name": "Report 2",
        "description": "Report Description",
        "createdBy": "TRAINING1",
        "id": "0653F758E5264C49E10000000A4E740E",
        "created": "2020-02-14T14:27:56.371Z",
        "changed": "2020-02-14T14:27:56.371Z",
        "isTemplate": false,
        "isSample": false,
        "models": [
            {
                "description": "Model description",
                "id": "id of the model",
                "isPlanning": true
            },
            {
                "description": "Model description",
                "id": "id of the model",
                "isPlanning": true
            },
            {
                "description": "Model description",
                "id": "id of the model",
                "isPlanning": true
            },
          
        ],
        "changedBy": "TRAINING1",
        "openURL": "URL of the report"
    },
    {
        "name": "Report Name 3",
        "description": "Report description 3",
        "createdBy": "TRAINING1",
        "id": "0653F758E5264C49E10000000A4E740E",
        "created": "2020-02-14T14:27:55.010Z",
        "changed": "2020-02-14T14:27:55.010Z",
        "isTemplate": false,
        "isSample": false,
        "models": [
            {
                "description": "description of the model",
                "id": "id of the model",
                "isPlanning": true
            },
            {
                "description": "model description",
                "id": "this is an id",
                "isPlanning": true
            },
            {
                "description": "model description",
                "id": "this is an id",
                "isPlanning": true
            }
        ],
        "changedBy": "TRAINING1",
        "openURL": "URL of the report"
    }
]
我想成为的图表如下:

我尝试的查询如下:

UNWIND $propsArray as props
      MERGE (sac:sacreports { id: props.id })
        ON CREATE
          SET sac = {id: props.id, name: props.name }
          UNWIND props.models as model
          MERGE (m: sacmodels {id: model.id})
          ON CREATE SET m = {id: model.id, description: model.description }
          ON MATCH SET m = {id: model.id, description: model.description }
        ON MATCH 
          SET sac = {id: props.id, name: props.name, description: props.description }
          UNWIND props.models as model
          MERGE (m: sacmodels {id: model.id})
          ON CREATE SET m = {id: model.id, description: model.description }
          ON MATCH SET m = {id: model.id, description: model.description }
          
      RETURN sac
我得到以下错误:Neo4jError:WITH在合并和展开之间是必需的(第7行第11列(偏移量:181))

对如何执行此操作有何建议


提前谢谢

我认为CREATE上的
和MATCH上的
只支持一个
SET
子句。而且,在查询中从不在报表和模型之间创建关系。如果您是根据节点的id进行合并,则不希望在CREATE
语句中覆盖它。我将使用以下查询:

UNWIND $propsArray as props
      MERGE (sac:sacreports { id: props.id })
        ON CREATE SET sac += {name: props.name , description: props.description}
      WITH sac, props
      UNWIND props.models as model
          MERGE (m: sacmodels {id: model.id})
          ON CREATE SET m += {description: model.description }
          MERGE (sac)-[:IS_USED_IN]->(m)

谢谢你的回复。我没有关系的原因是我无法创建节点。尝试查询时,我得到以下错误:Neo4jError:WITH是合并和展开之间必需的(第5行第9列(偏移量:177))“将props.models作为模型展开”