0
votes

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

1 Answers

1
votes

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.