You can execute Cypher queries with:
GraphDatabaseService db = ...;
// from version 2.2.x onwards
db.execute("your cypher statement");
// before version 2.2.x
ExecutionEngine engine = new ExecutionEngine(db)
engine.execute("your cypher statement");
If you're using Neo4j before v2.2, please note that ExecutionEngine
is meant to be instantiated as a singleton, so that execution plans will be properly cached.
If you have got strong performance constraints, might want to play with TraversalDescription
and customize the many available parameters and define a traversal callback if needed. The key is to ensure you traverse as little node as required.
You should know though that Cypher execution is being more and more performant, last version (2.2) brings lots of improvements.