简体   繁体   中英

Bulbs neo4j embedding, and deletion in cypher

I use the REST API of neo4j via bulbs and I tried to delete a node together with all associated edges via cypher like this:

from bulbs.neo4jserver import Graph as Neo4jGraph
db = Graph()

query = '''START d=node(57)
           MATCH d-[r]-()
           DELETE d,r
        '''
t = db.cypher.execute(query)

(where db is the neo4j-database-Handler).

... and it doesnt seem to work out like that. A long error report follows:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tobias/Esk/Dev/liquidDemocracyLight/venv/local/lib/python2.7/site-packages/bulbs/neo4jserver/cypher.py", line 31, in execute
    return self.client.cypher(query, params)
  File "/home/tobias/Esk/Dev/liquidDemocracyLight/venv/local/lib/python2.7/site-packages/bulbs/neo4jserver/client.py", line 403, in cypher
    resp = self.request.post(path, params)
  File "/home/tobias/Esk/Dev/liquidDemocracyLight/venv/local/lib/python2.7/site-packages/bulbs/rest.py", line 126, in post
    return self.request(POST, path, params)
  File "/home/tobias/Esk/Dev/liquidDemocracyLight/venv/local/lib/python2.7/site-packages/bulbs/rest.py", line 181, in request
    return self.response_class(http_resp, self.config)
  File "/home/tobias/Esk/Dev/liquidDemocracyLight/venv/local/lib/python2.7/site-packages/bulbs/neo4jserver/client.py", line 217, in __init__
    self.handle_response(response)
  File "/home/tobias/Esk/Dev/liquidDemocracyLight/venv/local/lib/python2.7/site-packages/bulbs/neo4jserver/client.py", line 249, in handle_response
    response_handler(response)
  File "/home/tobias/Esk/Dev/liquidDemocracyLight/venv/local/lib/python2.7/site-packages/bulbs/rest.py", line 36, in bad_request
    raise ValueError(http_resp)
ValueError: ({'status': '400', 'content-length': '3989', 'content-encoding': 'UTF-8', 'server': 'Jetty(6.1.25)', 'access-control-allow-origin': '*', 'content-type': 'application/json'}, '{\n  "message" : "expected return clause\\n\\"           DELETE d,r\\"\\n            ^",\n  "exception" : "org.neo4j.server.rest.repr.BadInputException: expected return clause\\n\\"           DELETE d,r\\"\\n 

Am I doing something wrong? Isn't it possible to delete nodes through cypher-querys via bulbs?

It looks like you're running an old version of Neo4j? DELETE was only added in 1.8.

Bulbs has a built-in method for deleting a node/vertex with all its relationships.

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> g.vertices.delete(57)

See http://bulbflow.com/docs/api/bulbs/element/#vertex-proxy

To do this, the Bulbs delete() method uses a Gremlin script under the hood because Neo4j Server doesn't provide a single endpoint to delete a vertex along with all its incident edges.

Here's what the code looks like:

Notice the above Gremlin script is using the Blueprints removeVertex() method (which is built into Neo4j Server) because it takes care of removing all the incident edges for you.

See https://github.com/tinkerpop/blueprints/blob/master/blueprints-neo4j-graph/src/main/java/com/tinkerpop/blueprints/impls/neo4j/Neo4jGraph.java#L409

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