1

I am making a search engine application using Node.js and Neo4j that allows users to submit a graph traversal query via a web-based user interface. I want to give users the option to cancel a query after it has been submitted (i.e. if a user decides to change the query parameters). Thus, I need a way to abort a query using either a command from a Node.js-to-Neo4j driver or via Cypher query.

After a few hours of searching, I haven't been able to find a way to do this using any of the Node.js-to-Neo4j drivers. I also can't seem to find a cypher query that allows killing of a query. Am I overlooking something, or is this not possible with Neo4j? I am currently using Neo4j 2.0.4, but I am willing to upgrade to a newer version of Neo4j if it has query killing capabilities.

Shrey Gupta
  • 5,509
  • 8
  • 45
  • 71

1 Answers1

4

Starting from Neo4j version 2.2.0, it's possible to kill queries from the UI and via the REST interface. I don't know if existing nodejs drivers support this feature, but if not you can still achieve the same functionality by making HTTP request to the REST interface.

If you run a query in the browser in version 2.2.x or later, you will notice that there is an (X) close link at the top-right corner of the area where the queries are executed and displayed.

You can achieve the same results by wrapping your queries in transactions and rolling them back. In fact, I just opened the web inspector to see how the browser UI was canceling the running queries.

I think this would be the recommended approach:

  1. Begin a transaction with the Cypher query you want to run. The transaction will be assigned an identifier, i.e. request POST http://localhost:7474/db/data/transaction and response with Location: http://localhost:7474/db/data/transaction/7
  2. If you want to cancel the query, delete the transaction using the identifier you got in step 1, i.e. DELETE http://localhost:7474/db/data/transaction/7

You will find more info about the Transactional Cypher HTTP Endpoint and examples in the official docs.

Update: node-neo4j seems to support transaction handling, including rollback. See docs.

albertoperdomo
  • 1,941
  • 12
  • 14
  • Will using the approach of wrapping the query in a transaction work with 2.0.x versions of neo4j, or is this a new feature of 2.2.x? – Shrey Gupta Apr 14 '15 at 19:22
  • AFAIK it will not. It's possible to begin, commit and rollback transactions but I don't think it's possible to cancel the query execution. – albertoperdomo Apr 14 '15 at 19:36
  • Okay, it looks like I'll be upgrading my Neo4j instance to 2.2.x then. Thank you! – Shrey Gupta Apr 14 '15 at 19:46