Neo4j demo

来自ling
跳转至: 导航搜索

https://www.cnblogs.com/jpfss/p/11491986.html Neo4j最短路径问题

MATCH p=shortestPath((bacon:`方剂学` {name:"桂枝汤"})-[*]-(meg:`方剂学` {name:"承气汤"})) RETURN p
MATCH (p1:`方剂学` {name:"桂枝汤"}),(p2:`方剂学`{name:"承气汤"}),p=shortestpath((p1)-[*..10]-(p2))RETURN p
MATCH (n:`test`) -[r]-(m) delete r
MATCH (n:`test`) delete n
create (n:`test`{name:'首页'}) return id(n)
CREATE (database:Database {name:"Neo4j"})-[r:SAYS]->(message:Message {name:"Hello World!"}) RETURN database, message, r
MATCH (n1)-[r]->(n2) RETURN r, n1, n2 LIMIT 25
MATCH (n) RETURN count(distinct labels(n))   call db.labels(); 
match(n:`方剂学`),(m:`方剂学`) where id(n)=1 and id(m)=81 create (n)-[r:RE {name:'1'}]->(m) return r

MATCH (n:`方剂学`) <-[r]->(m) where n.name='麻黄汤' and m.name='甘草' and r.name='1' return distinct r limit 1
MATCH (n:`%s`) <-[r]->(m) where n.name='%s' and m.name='%s' and r.name='1' return distinct n,r,m limit 1
MATCH (n:`%s`) where n.name='%s' RETURN distinct(n) limit %s 
MATCH (n)
WITH DISTINCT labels(n) AS labels
UNWIND labels AS label
RETURN DISTINCT label
ORDER BY label
MATCH (n) RETURN distinct labels(n), count(*)

MATCH (n:`test`) -[r]-(m) delete r MATCH (n:`test`) delete n

按id删除

MATCH (n:`%s`) -[r]->(m) where id(r)=%s delete r

重复关系

MATCH (a)-[r:RE]->(b) WITH a, b, TAIL (COLLECT (r)) as rr WHERE size(rr)>0
FOREACH (r IN rr | DELETE r)
MATCH (a)-[r:RE]->(b) where a.name=b.name
delete r
GraphDatabaseService db = (new GraphDatabaseFactory()).newEmbeddedDatabase(pathToDatabase);
ResourceIterable<Label> labs = GlobalGraphOperations.at(db).getAllLabels();
 MATCH (n:`test`)  RETURN distinct(n) limit 100
 [{"n":{"id":0,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"fx","value":653.4446105957031},{"key":"fy","value":51.65875244140625},{"key":"entitytype","value":0},{"key":"name","value":"111"}]}},{"n":{"id":1,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"r","value":30},{"key":"color","value":"#ff4500"},{"key":"name","value":"333"}]}},{"n":{"id":2,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"fx","value":536.665032638807},{"key":"r","value":30},{"key":"fy","value":112.18122000521251},{"key":"color","value":"#ff4500"},{"key":"name","value":"dafd"}]}},{"n":{"id":3,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"r","value":30},{"key":"color","value":"#ff4500"},{"key":"name","value":"111"},{"key":"uuid","value":0}]}},{"n":{"id":4,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"r","value":30},{"key":"color","value":"#ff4500"},{"key":"name","value":"dsafdsfd"},{"key":"uuid","value":"4"}]}},{"n":{"id":5,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"r","value":30},{"key":"hasfile","value":1},{"key":"color","value":"#2C6792"},{"key":"name","value":"fdsafdasfd"},{"key":"uuid","value":"5"}]}},{"n":{"id":6,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"r","value":30},{"key":"color","value":"#ff4500"},{"key":"name","value":"111"},{"key":"uuid","value":0}]}},{"n":{"id":7,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"r","value":30},{"key":"color","value":"#ff4500"},{"key":"name","value":"111"}]}},{"n":{"id":8,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"r","value":30},{"key":"color","value":"#ff4500"},{"key":"name","value":"sfds"}]}},{"n":{"id":209,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"entitytype","value":0},{"key":"name","value":""}]}},{"n":{"id":210,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"entitytype","value":0},{"key":"name","value":""}]}}]

MATCH (n:`test`)<-[r]-> (m)  RETURN distinct(r) limit 100

[{"fx":653.4446105957031,"fy":51.65875244140625,"entitytype":0,"name":"111"},{"r":30,"color":"#ff4500","name":"333"},{"fx":536.665032638807,"r":30,"fy":112.18122000521251,"color":"#ff4500","name":"dafd"},{"r":30,"color":"#ff4500","name":"111","uuid":0},{"r":30,"color":"#ff4500","name":"dsafdsfd","uuid":"4"},{"r":30,"hasfile":1,"color":"#2C6792","name":"fdsafdasfd","uuid":"5"},{"r":30,"color":"#ff4500","name":"111","uuid":0},{"r":30,"color":"#ff4500","name":"111"},{"r":30,"color":"#ff4500","name":"sfds"},{"entitytype":0,"name":""},{"entitytype":0,"name":""}]

node

{"id":0,"labels":["test"],"previousDynamicLabels":[],"propertyList":[{"key":"fx","value":653.4446105957031},{"key":"fy","value":51.65875244140625},{"key":"entitytype","value":0},{"key":"name","value":"111"}]}

relation

[{"r":{"endNode":1,"id":0,"propertyList":[{"key":"name","value":"has"}],"startNode":0,"type":"RE"}},{"r":{"endNode":1,"id":3,"propertyList":[{"key":"name","value":""}],"startNode":4,"type":"RE"}},{"r":{"endNode":1,"id":20,"propertyList":[{"key":"name","value":""}],"startNode":2,"type":"RE"}},{"r":{"endNode":2,"id":21,"propertyList":[{"key":"name","value":""}],"startNode":4,"type":"RE"}},{"r":{"endNode":2,"id":2,"propertyList":[{"key":"name","value":""}],"startNode":5,"type":"RE"}},{"r":{"endNode":4,"id":4,"propertyList":[{"key":"name","value":""}],"startNode":3,"type":"RE"}},{"r":{"endNode":3,"id":1,"propertyList":[{"key":"name","value":""}],"startNode":5,"type":"RE"}},{"r":{"endNode":7,"id":22,"propertyList":[{"key":"name","value":""}],"startNode":4,"type":"RE"}},{"r":{"endNode":6,"id":23,"propertyList":[{"key":"name","value":""}],"startNode":7,"type":"RE"}},{"r":{"endNode":8,"id":5,"propertyList":[{"key":"name","value":"1"}],"startNode":7,"type":"RE"}}]

{"code":200,"data":{"node":[{"fx":653.4446105957031,"fy":51.65875244140625,"entitytype":0,"name":"111","uuid":"0"},{"r":30,"color":"#ff4500","name":"333","uuid":"1"},{"fx":536.665032638807,"r":30,"fy":112.18122000521251,"color":"#ff4500","name":"dafd","uuid":"2"},{"r":30,"color":"#ff4500","name":"111","uuid":"3"},{"r":30,"color":"#ff4500","name":"dsafdsfd","uuid":"4"},{"r":30,"hasfile":1,"color":"#2C6792","name":"fdsafdasfd","uuid":"5"},{"r":30,"color":"#ff4500","name":"111","uuid":"6"},{"r":30,"color":"#ff4500","name":"111","uuid":"7"},{"r":30,"color":"#ff4500","name":"sfds","uuid":"8"},{"entitytype":0,"name":"","uuid":"209"},{"entitytype":0,"name":"","uuid":"210"}],"relationship":[{"sourceid":"0","targetid":"1","name":"has","uuid":"0"},{"sourceid":"4","targetid":"1","name":"","uuid":"3"},{"sourceid":"2","targetid":"1","name":"","uuid":"20"},{"sourceid":"4","targetid":"2","name":"","uuid":"21"},{"sourceid":"5","targetid":"2","name":"","uuid":"2"},{"sourceid":"3","targetid":"4","name":"","uuid":"4"},{"sourceid":"5","targetid":"3","name":"","uuid":"1"},{"sourceid":"4","targetid":"7","name":"","uuid":"22"},{"sourceid":"7","targetid":"6","name":"","uuid":"23"},{"sourceid":"7","targetid":"8","name":"1","uuid":"5"}]},"msg":null}