I am Hack Sparrow
Captain of the Internets.

Neo4j Tutorial – Introduction to Neo4j

Introduction to Neo4j

When I set out to know Neo4j better, I couldn't easily find something which would get me started with Neo4j. Most articles and videos talked about theory or assumed you already knew the basics, and the examples were in Java; I couldn't find a straightforward tutorial which would show a non-Java guy how to start interacting with Neo4j.

This tutorial is not meant to be an in-depth tutorial on Neo4j or graph databases. The intention of this introductory tutorial is to point you at the right directions on getting started with Neo4j.

What is Neo4j?

Neo4j is a graph database. Graph databases are a database system which is composed of nodes (vertices) and relationships (edges) instead of tables, which is a completely different paradigm from SQL. That's all I would say at this stage. Once you start interacting with the database, you will have a better understanding of how Neo4j and graph databases work. In the meantime let me link you to Graph Database entry on Wikipedia and an explanation here.

Some relevant videos

Emil Eifrem introduces you to the world of graphs

YouTube Preview Image

Introduction to Graph Databases

YouTube Preview Image

The Pathology of Graph Databases by Marko A. Rodriguez

Installing and setting up Neo4j

Download Neo4j from http://neo4j.org/download/. Unarchive it. If you are on a *nix do this:

$ tar -zxvf neo4j-community-1.6.M02-unix.tar.gz

Once unarchived, you should see something like this:

-rw-r--r--@ 1 captain captain 15935 Dec 16 21:38 CHANGES.txt
-rw-r--r--@ 1 captain captain 36045 Dec 16 21:38 LICENSE.txt
-rw-r--r--@ 1 captain captain 85347 Dec 16 21:38 LICENSES.txt
-rw-r--r--@ 1 captain captain 3662 Dec 16 21:38 NOTICE.txt
-rw-r--r-- 1 captain captain 2042 Dec 16 21:38 README.txt
-rw-r--r--@ 1 captain captain 3895 Dec 16 21:36 UPGRADE.txt
drwxr-xr-x@ 10 captain captain 340 Dec 16 21:38 bin
drwxr-xr-x@ 8 captain captain 272 Dec 16 21:38 conf
drwxr-xr-x@ 7 captain captain 238 Dec 22 16:19 data
drwxr-xr-x@ 10 captain captain 340 Dec 22 16:23 doc
drwxr-xr-x@ 17 captain captain 578 Dec 16 21:38 lib
drwxr-xr-x@ 3 captain captain 102 Dec 16 21:38 plugins
drwxr-xr-x@ 4 captain captain 136 Dec 16 21:38 system

The Neo4j manual is located in the doc directory. I would recommend checking out doc/manual/pdf/neo4j-manual.pdf (PDF version of the manual) and doc/manual/html/index.html (HTML version of the manual).

And it is in the bin directort you will find the Neo4j server and shell executables, along with other things.

captain:neo4j-community-1.6.M02 captain$ ls -l bin/
total 88
-rw-r--r--@ 1 captain captain 346 Dec 16 21:38 README.txt
drwxr-xr-x@ 3 captain captain 102 Dec 16 21:38 lib
-rwxr-xr-x@ 1 captain captain 12302 Dec 16 21:38 neo4j
-rwxr-xr-x@ 1 captain captain 3442 Dec 16 21:38 neo4j-shell
-rwxr-xr-x@ 1 captain captain 494 Dec 16 21:38 org.neo4j.coord.plist
-rwxr-xr-x@ 1 captain captain 479 Dec 16 21:38 org.neo4j.server.plist
drwxr-xr-x@ 4 captain captain 136 Dec 16 21:38 templates
-rwxr-xr-x@ 1 captain captain 8526 Dec 16 21:38 utils

To start Neo4j, do this:

$ bin/neo4j start

To stop:

$ bin/neo4j stop

As simple as that. If you are planning on installing Neo4j as a service, refer this.

Now that you have Neo4j running, let's find out how to interact with it.

The command line Neo4j shell is located at bin/bin/neo4j-shell, using which you can browse around the database (much like browsing through a file system!). Along with that, Neo4j provides an amazing web admin panel at http://localhost:7474/webadmin/ (make sure Neo4j is running to access the panel). The admin panel, among other things, provides THREE different types of consoles to interact with your data - the standard Neo4j Shell, Gremlin, and HTTP. Neo4j Shell and Gremlin is best used for manual interaction with the data, and the HTTP shell is best used to see how your apps might interact with the Neo4j REST API.

Here is an example session of Neo4j interaction from the shell.

The ideal approach of familiarizing oneself with how Neo4j works would be via the Neo4j shell. Unfortunately, as hard as I tried, I couldn't find a way to create independent nodes using the Neo4j shell, which makes no sense to me at all. You have rmnode and rmrel to delete nodes and relationships respectively, but apparently you use mkrel to create both nodes and relationships! I hope a more sensible way of creating nodes and relationships is introduced later.

Querying the database from the Neo4j shell is done using the Cypher query language. Details about the language can be found at http://docs.neo4j.org/chunked/1.6.M02/cypher-query-lang.html.

Indexes in Neo4j

Neo4j supports two types of indexes - node indexes and relationship indexes. Node indexes are used for searching nodes, and relationship indexes are used for searching relationships. Details about indexes in Neo4j can be found at http://docs.neo4j.org/chunked/snapshot/indexing.html.


As I mentioned at the beginning, this tutorial is not meant to be a detailed Neo4j tutorial, it is supposed to be more like a resource pointer to help oriented newbies to Neo4j. I actually started writing this tutorial with the intention of making it a one stop Neo4j tutorial page, but figured mid way that the topic is too vast and I would end up with a HUGEEEEE one-page tutorial which would only tire my readers. So I decided I would rather create a series of Neo4j tutorials, which starts with this one. I will be covering important aspects of Neo4j one by one in the coming days with excellent examples and explanation. Stay tuned.

3 Responses to “Neo4j Tutorial – Introduction to Neo4j”

  1. Luiz says:

    Thanks for sharing! That’s very helpful.

  2. Deo Shao says:

    Thank you for this write up! You’ve tickled all my enthusiasm to Neo4j

  3. Damith Senanayake says:

    Thanks, I wish I stumbled across this earlier. Would have saved me a lot of time and effort it took me to configure Neo4j on Linux. Please also modify to address the issue of requiring the Sun JDK for installing to replace the relevant lines on the installation config file.

Make a Comment