Match/delete whole subgraph in Neo4j

馋奶兔 提交于 2019-12-11 02:28:43

问题


Given there is a big graph in my database and I want to delete a whole subgraph of that, where I only know the starting node of this subgraph. Is it possible to write a cypher query to match and delete this whole subgraph?

Caveat: I don't know more of the subgraph as in which node it starts.


回答1:


Yes, you can expand from a single node to all subgraph nodes via APOC Procedures path expander, optionally with filters on the relationships or nodes to traverse, and with an optional max depth.

You need to use the expandConfig() procedure, and use NODE_GLOBAL uniqueness.

MATCH (s:Node)
WHERE s.name = 'start'
CALL apoc.path.expandConfig(s, {uniqueness:'NODE_GLOBAL'}) YIELD path
WITH LAST(NODES(path)) as subgraphNode
...

Eventually there will be a subgraphNodes() procedure to wrap this to better highlight the functionality.



来源:https://stackoverflow.com/questions/42227258/match-delete-whole-subgraph-in-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!