Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete node and relationships using cypher query over REST API

Tags:

neo4j

cypher

I'm playing with 2.0 M6 neo4j server (oracle jdk7 on win7 64).

I'm trying to delete a node and its relationships using a single cypher query over the REST API.

The query I create (which works if I run it in the browser UI) looks like:

START n = node( 1916 ) MATCH n-[r]-() DELETE n, r

Which by the time I put it through gson comes out as:

{"query":"START n \u003d node( 1916 ) MATCH n-[r]-() DELETE n, r"}

Which when sent to the server gets the response:

{
  "columns" : [ ],
  "data" : [ ]
}

My test fails because the node can still be found in neo4j server by its id...

If I simplify my query to just delete a node (that has no relationships) so its:

START n = node( 1920 )  DELETE n

Which becomes

{"query":"START n \u003d node( 1920 )  DELETE n"}

Then the node is deleted.

Have I missed something?

Thanks, Andy

like image 400
user2926169 Avatar asked Oct 27 '13 22:10

user2926169


People also ask

How do I delete a node in Cypher?

To delete nodes and relationships using Cypher, use the DELETE clause. The DELETE clause is used within the MATCH statement to delete whatever data was matched. So, the DELETE clause is used in the same place we used the RETURN clause in our previous examples.

How delete all nodes and relationships in Neo4j give example?

There is a method to delete a node and all relationships related to that node. Use the DETACH DELETE statement: Example: MATCH (Kohli:player{name: "Virat Kohli"}) DETACH DELETE Kohli.

How do I delete a particular relationship in Neo4j?

In Neo4j to delete a node or relations between nodes you have to use DELETE clause. To delete any node you need DELETE clause with the MATCH statement, the MATCH statement data will find the specific node and whichever node is matched with the statement that node will be vanished.

Which endpoint is required when you want to execute a Cypher query using the REST API?

The Neo4j transactional HTTP endpoint allows you to execute a series of Cypher statements within the scope of a transaction.


1 Answers

For neo4j 2.0 you would do

START n=node(1916)
OPTIONAL MATCH n-[r]-()
DELETE r, n;
like image 126
Leland Cope Avatar answered Sep 28 '22 20:09

Leland Cope