运行参数化neo4j cypher查询

时间:2016-10-23 16:36:44

标签: neo4j

以下是对参数化列表中提到的每种关系类型重复的密码查询,并且每种关系类型都具有要添加到连接节点的特定属性和值。根据neo4j,不可能参数化关系类型。无论如何使用cypher解决这个问题?还是与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 个答案:

答案 0 :(得分:1)

Neo4j无法与参数化类型建立关系。但是有一个APOC程序允许这样做。请参阅creating data section,apoc.create.relationship()是您正在寻找的程序。