简体   繁体   English

如何在neo4j中更新子图

[英]How to update a subgraph in neo4j

I am working on a Neo4j project, I am trying to update a current graph. 我正在开发Neo4j项目,正在尝试更新当前图形。 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... / *表示关系为:E-> C /表示关系为:A-> B,B-> D,B-> E等

So what I want to do is be able to update this graph for example if F is deleted. 因此,我想做的就是能够更新此图,例如如果F被删除。 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). 我不想再次在服务中生成整个图,而是要获取neo4j中包含的图并对其进行更新(其中F不再存在了)。

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) 目前我尝试过的是,将图从neo4j导入JAVA,生成samller子图(C的子图)(这给了我两个哈希图:一个带有关系,一个带有节点)

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. 您应该为此使用Cypher

You can just MATCH to your 'F' node and DETACH DELETE it. 您可以仅匹配到“ F”节点,然后删除它。 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: 假设现在您的节点上有标签(我假设为:Node),则可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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