简体   繁体   中英

How to update a subgraph in neo4j

I am working on a Neo4j project, I am trying to update a current graph. I am going to give an example on what I am trying to accomplish:

First I have the following graph:

                                    A
                                   / \
                                  B   C
                                /  \ /* \
                               D    E   F

The /* means that the relationship is : E -> C The / means that the relationship is: A->B, B->D, B->E, etc...

So what I want to do is be able to update this graph for example if F is deleted. I do not want to generate the whole graph in my service again, but grab the graph I have in neo4j and make an update on it (Where F is not there anymore).

Currently What I have tried, Is getting the graph from neo4j into JAVA, generating the samller subgraph (the subgraph for C) (which gives me two hash maps: one with the relationships one with the nodes)

and then checking one by one trying to see if they are the same, if there is a change then replace it. Is there a faster way of doing this?

You should be using Cypher for this.

You can just MATCH to your 'F' node and DETACH DELETE it. This will delete the node and any relationships on it.

Assuming you have labels on your nodes (I'll assume :Node) for now, you can do:

MATCH (f:Node {name:'F'})
DETACH DELETE f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM