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
Introduction to Graph Databases
The Pathology of Graph Databases by Marko A. Rodriguez
Installing and setting up Neo4jDownload 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/
-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
$ 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
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.