Neo4j Cypher查询删除节点和所有子节点及关系

Neo4j Cypher查询删除节点和所有子节点及关系,neo4j,cypher,Neo4j,Cypher,这是我在Cypher中的Neo4j代码的一部分: CREATE (search{id : '0', title : 'Begin Search'}), (telephone { id : '2' , title : 'Telephone' }), (tablet { id : '1' , title : 'Tablet' }), (printer { id : '3' , title : 'Printer' }), (scanner { id : '4' , title : 'Scanner'

这是我在Cypher中的Neo4j代码的一部分:

CREATE 
(search{id : '0', title : 'Begin Search'}),
(telephone { id : '2' , title : 'Telephone' }),
(tablet { id : '1' , title : 'Tablet' }),
(printer { id : '3' , title : 'Printer' }),
(scanner { id : '4' , title : 'Scanner' }),
(laptop { id : '5' , title : 'Laptop' }),
(pc { id : '6' , title : 'Personal Computer' }),
(monitor { id : '7' , title : 'Monitor' }),

(galaxykids7wifi { id : '100' , model : ' Galaxy Tab 3 Kids 7.0 wi-fi', brand : 'Samsung', processor : 'Dual-Core Processor', network : 'Android Jelly Bean 4.1', memory : '8 Gb' , screen : '7 inches ', wieght : '302 g', dimensions : '111.1*188*9.9 mm' , battery : '4000 mAh', wifi : '802.11', wifi_speed : '2.4 + 5 GHz', wifi_type : 'a/b/g/n', ram : '1 Gb', kamera : '3 Mpix' }),
(galaxytab310wifi3g { id : '101' , model : ' Galaxy Tab 3 10.1 wi-fi + 3 G', brand : 'Samsung', processor : 'Dual-Core Intel Atom Processor', network : 'Android 2.2', memory : '16 Gb', memory1 : '32 Gb' , screen : '10.1 inches ', wieght : '512 g', dimensions : '176.1*243,1*7.45 mm' , battery : '6800 mAh', wifi : '802.11', wifi_speed : '2.4 + 5 GHz', wifi_type : 'a/b/g/n', ram : '1 Gb', kamera : '3 Mpix' }),
(galaxytab310wifi { id : '102' , model : ' Galaxy Tab 3 10.1 wi-fi', brand : 'Samsung', processor : 'Dual-Core Intel Atom Processor', network : 'Android 2.2', memory : '16 Gb',memory1 : '32 Gb' , screen : '10.1 inches ', wieght : '510 g', dimensions : '176.1*243,1*7.45 mm' , battery : '6800 mAh', wifi : '802.11', wifi_speed : '2.4 + 5 GHz', wifi_type : 'a/b/g/n', ram : '1 Gb', kamera : '3 Mpix' }), 
(galaxytab38wifi3g { id : '103' , model : ' Galaxy Tab 3 8.0 wi-fi + 3 G', brand : 'Samsung', processor : 'Dual-Core Processor', network : 'Android JB 4.2.2', memory : '16 Gb', memory1 : '32 Gb' , screen : '8 inches ', wieght : '316 g', dimensions : '123.8*209.8*7.4 mm' , battery : '4450 mAh', wifi : '802.11', wifi_speed : '2.4 + 5 GHz', wifi_type : 'a/b/g/n', ram : '1.5 Gb', kamera : '5 Mpix'}),
(galaxytab38wifi { id : '104' , model : ' Galaxy Tab 3 8.0 wi-fi', brand : 'Samsung', processor : 'Dual-Core Processor', network : 'Android JB 4.2.2', memory : '16 Gb', memory1 : '32 Gb' , screen : '8 inches ', wieght : '314 g', dimensions : '204.8*123.8*7.4 mm' , battery : '4450 mAh', wifi : '802.11', wifi_speed : '2.4 + 5 GHz', wifi_type : 'a/b/g/n', ram : '1.5 Gb', kamera : '5 Mpix'}),

(search)<-[:TYPE]-(tablet),
(search)<-[:TYPE]-(telephone),
(search)<-[:TYPE]-(printer),
(search)<-[:TYPE]-(scanner),
(search)<-[:TYPE]-(laptop),
(search)<-[:TYPE]-(pc),
(search)<-[:TYPE]-(monitor),

(tablet)<-[:TYPE]-(galaxykids7wifi),
(tablet)<-[:TYPE] -(galaxytab310wifi3g),
(tablet)<-[:TYPE]-(galaxytab310wifi),
(tablet)<-[:TYPE]-(galaxytab38wifi3g),
(tablet)<-[:TYPE]-(galaxytab38wifi)
我猜问题在于查询无法读取id为1的节点在哪里,但这毫无意义。如果可能的话,请帮助我

像这样的查询不起作用:

start n=node(1) 
match n-[*]-x 
WITH x 
MATCH x-[r]-() delete x,r
编辑

下面的两个答案也不起作用。我正在运行Neo4j 2.0.0-M06

(一)

当您引用节点(1)时,您并不是指具有值为1的id属性的节点,而是请求具有内部id 1的节点(由Neo4j内部维护,您无法控制分配此值)。因此,这可能是它无法定位id为1的节点的原因

如果您使用的是2.0,那么类似的功能将起作用(未经测试):


Luane已经回答了错误,因此也回答了问题(如果错误消失,请将他的回答标记为已接受),但是如果您想通过
(tablet)
删除图表中的所有内容,您还需要一个更好的模式。类似这样的东西应该适用于您的数据样本

MATCH (n {id:'1'})<-[r]-x-[ss*0..]-y
WHERE NOT r IN ss  //I expected relationship uniqueness to ensure that 'r' is not traversed twice, but it didn't so I added an explicit check
OPTIONAL MATCH n-[t]->()
FOREACH (s IN ss | DELETE s)
DELETE r,y,t,n

MATCH(n{id:'1'})我已重新格式化了您的问题,使其可读。请参阅此处了解下次如何自己完成:您正在使用Neo4j的开发(未完成)版本。请使用发布的Neo4j 2.0 GA,如果您仍然有问题,可以发回。
MATCH (n {id:'1'})<-[r]-x-[ss*0..]-y
WHERE NOT r IN ss  
OPTIONAL MATCH n-[t]->()
FOREACH (s IN ss | DELETE s)
DELETE r,y,t,n

Error: Invalid input 'P' : expected 'r/R'
   "OPTIONAL MATCH n-[t]->()"
     ^
match (n {id : '1'})
optional match n-[r]-x
delete r,x

Invalid input 'o': expected whitespace, comment, a relationship patter, .....
"optional match n-[r]-x"
 ^
match (n {id : '1'})
optional match n-[r]-x
delete r,x
MATCH (n {id:'1'})<-[r]-x-[ss*0..]-y
WHERE NOT r IN ss  //I expected relationship uniqueness to ensure that 'r' is not traversed twice, but it didn't so I added an explicit check
OPTIONAL MATCH n-[t]->()
FOREACH (s IN ss | DELETE s)
DELETE r,y,t,n