Running parametrized neo4j cypher query

╄→гoц情女王★ 提交于 2019-12-12 03:46:27

问题


Given below is the cypher query which gets repeated for each relationship type as mentioned in parameterized list and each relationship type has specific property and value to be added to the connecting node. According the neo4j, it is not possible to parametrize relationship type. Is there anyway to address this using cypher? or with apoc?

Merge(n_device: Device{identifier: {deviceId}}) ON CREATE SET n_device.created=timestamp()
WITH n_device
OPTIONAL MATCH (n_device)-[r_prev:{deviceRel}{active:true}]->() 
WITH n_device, r_prev   
Merge(n_deviceOs: Device{{deviceRelProp}: {deviceRelPropVal}}) ON CREATE SET n_deviceOs :DeviceOs,  n_deviceOs.created=timestamp(), n_deviceOs.newNode=true
WITH n_device, n_deviceOs, r_prev
Merge (n_device)-[r_cur:{deviceRel}]->(n_deviceOs) ON CREATE SET r_cur.active=true, r_cur.created=timestamp()
WITH n_deviceOs, r_prev
Match(n_deviceOs) where n_deviceOs.newNode=true set r_prev.active = false, r_prev.modified=timestamp()
REMOVE n_deviceOs.newNode

"params": {
    "deviceId": "1234",
    "deviceRel": ["HAS_DEVICE_OS", "HAS_DEVICE_OSINFO", "HAS_DEVICE_MODEL", "HAS_DEVICE_APPVERSION"],
    "deviceRelProp": ["os", "osinfo", "model", "version"],
    "deviceRelPropVal": ["android", "kitkat", "samsung", "1.64.2"]
}

回答1:


Neo4j can't create a relationship with a parameterized type. But there is an APOC Procedure which allows this. See the creating data section, apoc.create.relationship() is the procedure you're looking for.



来源:https://stackoverflow.com/questions/40205200/running-parametrized-neo4j-cypher-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!