2016-03-02 85 views
0

我有一個與py2neo的neo4j Cypher相關的基本操作。我要讀的JSON,其中JSON對象結構看起來像Neo4j - SET使用CYPHER從節點讀取列表的標籤列表,從json文件讀取列表

{ "ip":"0.0.2.2", 
    "location":"uk", 
    "uptime":"30", 
    "services:["irqbalance","IPsec","nfsd","iscsi","rdisc","iscsi","irqbalance","sssd"]} 

注意的是,物業服務有價值觀,我需要將它們作爲標籤的列表對象。

這裏是我的方法,我可以加載沒有標籤的json,但無法設置標籤。

我的查詢:

With {data} As machines 
UNWIND machines.Servers as server 
MERGE (a{ip:server.ip,uptime:server.uptime,location:server.location}) 

與此查詢我填充節點,但如何設置標籤在同一個查詢。

+1

你不能從參數 –

+0

任何其他方式設置的標籤這樣做 –

+0

在應用層面查詢生成過程中添加標籤 –

回答

1

您不能從參數設置標籤。相反,您應該使用標籤格式化字符串。

labels = ['Some', 'List', 'With', 'Your', 'Labels'] 
labels = ':'.join(labels) 

query = (
    "With {data} As machines " 
    "UNWIND machines.Servers as server " 
    "MERGE (a:" + labels + ")" 
) 

輸出:

In [22]: query 
Out[22]: 'With {data} As machines UNWIND machines.Servers as server MERGE (a:Some:List:With:Your:Labels)'