The top 10 ways to get to know Neo4j


The top 10 ways to get to know Neo4j

Today is a big day in Neo4j land because after ten long years of development and seven years of commercial 24/7 production we just announced Neo4j 1.0!

We’re very excited about this and this post will outline the ten most interesting and fun ways of getting started with Neo4j. Without further ado, let’s go!
  1. Wait, what is Neo4j?

    Neo4j is a graph database, that is, it stores data as nodes and relationships. Both nodes and relationships can hold properties in a key/value fashion. Here’s a small example:
    Neo4j Graph Database Example of the Matrix
    You can navigate the structure either by following the relationships or use declarative traverser features to get to the data you want.
  2. Introduction

    For a high-level, 9 minutes cocktail-party introduction of Neo4j, check out this interview with Emil Eifrem:

    (blip.tv)
    To watch a longer introduction, see the no:sql(east) 2009 presentation by Emil Eifrém
  3. Handling complexity

    Most applications will not only have to scale to a huge volumes, but also scale to the complexity of the domain at hand. Typically, there may be many interconnected entities and optional properties. Even simple domains can be complex to handle because of the queries you want to run on them, for example to find paths. Two coding examples are the social network example (partial Ruby implementation) and the Neo4j IMDB example (Ruby variation of the code). For more examples of different domains modeled in a graph database, visit the Domain Modeling Gallery
  4. Storing objects

    The common domain implementation pattern when using Neo4j is to let the domain objects wrap a node, and store the state of the entity in the node properties. To relieve you from the boilerplate code needed for this, you can use a framework like jo4neo (intro, blog posts), where you use annotations to declare properties and relationships, but still have the full power of the graph database available for deep traversals and other graphy stuff. Here’s a code sample showing jo4neo in action:
    public class Person {
    //used by jo4neo
    transient Nodeid node;
    //simple property
    @neo String firstName;
    //helps you store a java.util.Date to neo4j
    @neo Date date;
    // jo4neo will index for you
    @neo(index=true) String email;
    // many to many relation
    @neo Collection roles;

    /* normal class oriented
    * programming stuff goes here
    */
    }
    Another way to persist objects is by using the neo4j.rb Neo4j wrapper for Ruby. Time for a few lines of sample code again:
    require "rubygems"
    require "neo4j"

    class Person
    include Neo4j::NodeMixin
    # define Neo4j properties
    property :name, :salary, :age, :country

    # define an one way relationship to any other node
    has_n :friends

    # adds a Lucene index on the following properties
    index :name, :salary, :age, :country
    end
  5. REST API

    Of course you want a RESTful API in front of the graph database as well. There’s been plenty of work going on in that area and here are some options:
    • The neo4j.rb Ruby bindings comes with a REST extension.
    • The neo4jr-simple Ruby wrapper has the neo4jr-social example project, which exposes social network data over a REST API.
    • Similarly, the Scala bindings has a companion example project which will show you how to set up a project exposing your data over REST.
    • Last but not least, Jim Webber has joined up with the core Neo4j team to create a kick-ass REST API. The current code base is only in the laboratory but a lot of people are already kicking its tires.
  6. Language bindings

    The Neo4j graph engine is written in Java, so you can easily add the jar file and start using the simple and minimalistic API right away. Your first stop should be the Getting started guide. Other language bindings:
    • Python – see PyCon 2010 too!
    • Ruby
    • Clojure
    • Scala
    • Java object mapping
    • For Groovy, see the next section on frameworks.
    • Integration with PHP is worked on as well.
  7. Frameworks

    Work is being done on using Neo4j as backend of different frameworks. Follow the links to get more information!
  8. Tools

    • Shell: a command-line shell for browsing the graph and manipulate it.
    • Neoclipse: Eclipse plugin (and standalone application) for Neo4j. Visual interface to browse and edit the graph.
    • Batch inserter: tool to bulk upload big datasets quickly.
    • Online backup: performs backup of a running Neo4j instance.
  9. Query languages

    Beyond using Neo4j programmatically, you can also issue queries using a query language. These are the supported options at the moment:
    • SPARQL: Neo4j can be used as a triple- or quadstore, and has SAIL and SPARQL implementations. Go to the components site to find out more about the related components.
    • Gremlin: a graph-based programming-language with different backend implementations in the works as well as a supporting toolset.
  10. Inspiration

    Have a look at the Neo4j in the wild page to see what others are doing with Neo4j. Here’s a selection:
Hopefully this post was a good starting guide to the Neo4j ecosystem. As always, please ask any questions on the mailing list or come hang out with us in the #neo4j channel on IRC.



Want to learn more about graph databases? Click below to get your free copy of O’Reilly’s Graph Databases ebook and discover how to use graph technologies for your application today.

Download My Ebook