Neo4j-core Code Climate Build Status Coverage Status PullReview stats

A simple Ruby wrapper around the Neo4j graph database that works with the server and embedded Neo4j API. This gem can be used both from JRuby and normal MRI. It can be used standalone without the neo4j gem.

Basic usage

Executing Cypher queries

To make a basic connection to Neo4j to execute Cypher queries, first choose an adaptor. Adaptors for HTTP and Embedded mode (jRuby only) are available (support for Neo4j 3.0's Bolt protocol is planned). You can create an adaptor like:

http_adaptor ='http://neo4j:[email protected]:7474')

# or

neo4j_adaptor ='/file/path/to/graph.db')

Once you have an adaptor you can create a session like so:

neo4j_session =

From there you can make queries with a Cypher string:

# Basic query
neo4j_session.query('MATCH (n) RETURN n LIMIT 10')

# Query with parameters
neo4j_session.query('MATCH (n) RETURN n LIMIT {limit}', limit: 10)

Or via the Neo4j::Core::Query class

query_obj =


Making multiple queries with one request is supported with the HTTP Adaptor:

results = neo4j_session.queries do
  append 'MATCH (n:Foo) RETURN n LIMIT 10'
  append 'MATCH (n:Bar) RETURN n LIMIT 5'

results[0] # results of first query
results[1] # results of second query

When doing batched queries, there is also a shortcut for getting a new Neo4j::Core::Query:

results = neo4j_session.queries do
  append query.match(:n).return(:n).limit(10)

results[0] # result


3.0+ Documentation:

2.x Documentation



Next Release In Progress In Master

Post an issue

Get Support


All new documentation will be done via our readthedocs site, though some old documentation has yet to be moved from our wiki (also there is the neo4j-core wiki)

Contact Us

StackOverflow Gitter Twitter


Original Author

Current Maintainers

Consulting support? Contact Chris and/or Brian


Pull request with high test coverage and good code climate values will be accepted faster. Notice, only JRuby can run all the tests (embedded and server db). To run tests with coverage: rake coverage.


Notice there are different license for the neo4j-community, neo4j-advanced and neo4j-enterprise jar gems. Only the neo4j-community gem is by default required.