Over a million developers have joined DZone.

Neo4j 2.0 Released: 5 Ways It Will Help You Kick Ass

DZone 's Guide to

Neo4j 2.0 Released: 5 Ways It Will Help You Kick Ass

· Database Zone ·
Free Resource

[This post was originally written by Peter Neubauer]

Christmas is near, and to ease the tension until the big event, we thought we'd give you an early present this year. Neo4j 2.0 - a graph database for everyone. We focused many of the enhancements around making our users successful and have the best time ever using a database.


We happily announce the final 2.0 release of Neo4j, which comes packed with new, exciting features that we can’t wait to tell you about. We’ve worked hard on this release for a long time and are very excited that now all comes together and you can enjoy the result of our efforts. Here are the 5 best all-new feature-sets of Neo4j 2.0:

1. All About U(X)

The New, Shiny Neo4j Browser

We completely rewrote the Neo4j Browser into a helpful visual workbench with a lot of focus on user happiness.

Most of the features are driven by better understanding the way users work with a graph database to develop their graph models and applications.

First of all the clean UI and helpful guides, help topics and your first graph app “Movies” will help you get started.

Then the powerful combination of a multiline Cypher query editor with insightful visualizations, tabular representations, drag-and-drop support and export features will be your daily companion. Styling your graph with a few clicks helps you to make your point.

To keep your work save, the Browser persists the history and you can store relevant queries to a set of built-in folders.

A query visualization in the new Neo4j browser of the MusicBrainz dataset

Stay tuned for more Neo4j Browser goodness in the near future. For now, download and install Neo4j, go to http://localhost:7474 and follow the guides! Make sure to explore the side-bars on the left for helpful tools and information.

The Windows Installer

A big share of the Neo4j user community works on Windows to develop applications. To make the experience on this platform more convenient, we now offer a native Windows Installer that also provides the correct Java Runtime out of the box. We install a Neo4j Desktop application on your system that helps you starting, stopping and configuring your Neo4j Server.

2. Labels on Nodes

This is the first time since the inception of Neo4j back in 2002 that we have decided to make a major change to the Property Graph Model (thus the major version number increment). It now has been enhanced by (optional) Labels on nodes. Labels are a way to denote which “roles” a node would have in your domain. In that regard it is not just a “type” information, but much more flexible and versatile. You can have as many labels on each node as you like.

In the past people have resorted to many ways of representing types and roles in a graph which were more or less cumbersome and performant. With labels all that is gone and you can now happily spread your label-love around your graph and focus on representing your real domain in your graph model.

  • l  Labels can denote nodes of the same characteristics, essentially giving you a way to introduce “Types” or “Tags” of nodes - subgraphs like Person, Product or ”things that have a timestamp property”.
  • l  Labels are a very effective way to avoid the “Type nodes” and other patterns, that were used in the past to represent types in the graph.
  • l  Labels are an anchor to attach other functionality like automatic indexes, constraints and more in a declarative and predictable manner.
  • l  Labels are fully optional, so your existing data models will still work.

A graph model with labels.

If you want to see one way to upgrade your existing graph structure to benefit from indexes, see another example of upgrading a Graph from 1.9 to 2.0.

You can upgrade your graph easily with labels, by executing cypher statements (optionally batched) like this:

MATCH (people)<-[r:IS_A]-(person)
WHERE id(people) = {id-of-type-node}
SET person:Person

3. Optional Schema

Wait, what we hear you say. Schema in an NoSQL database? It’s not like returning to relational schemas, rather being able to provide some additional meta-information to make your queries run better and your data being more consistent.

Automatic Indexes

With the Labels in place, we can provide indexing meta-information, solving some of the most common indexing patterns in a nice way - the Automatic Index. You now can declare an automatically indexed property on a labelled node like this in Cypher:


This index will index the existing data in the background. After becoming ONLINE it is transactionally updated. The index is then automatically used by the database in a query like this:

MATCH (n:Person {name:'Andres'})

Uniqueness Constraints

A very common pattern when working with any data is to make sure certain entities exist only once in your database, known as Uniqueness Constraints. Neo4j now supports this automatically, using the automatic indexes on labels, so you can define them like so:


This ensures that you won’t be able to create a second “Person” node with the same “name” property value. Such a query would fail. We also provide a “Get or Create” semantics with MERGE (see below).

4. Transactional HTTP Endpoint

In order to combine the convenience of HTTP with the power of real transactions across the wire over multiple HTTP requests containing many Cypher statements, we created a transactional Cypher HTTP endpoint. It lets you create a transaction by POSTing statements and parameters to the /db/data/transaction URL. This will create a transaction for you and return the inherent transaction URL. You then can post more statements to that URL, e.g. /db/data/transaction/4 and finally commit the transaction with a POST to /db/data/transaction/4/commit. This endpoints also streams all the data from and to the server so that minimum memory overhead is needed on both sides. And we finally reduced the amount of information transmitted for nodes, relationships and paths to the absolute minimum, just their properties.

5. More Cypher Functionality

We have been thinking and discussing thoroughly about how to make Cypher a more complete language, so that you can express your use-cases easily and don’t have to drop down to other APIs. Here are three of the many things we’ve worked on.


Instead of having the (a)-[?]-() pattern for optional relationships, we have opted for the more powerful approach of declaring OPTIONAL MATCHes, giving the possibility to not only declare single relationships, but whole patterns as optional. A simple example is the statement to delete all nodes and relationships in the database:



This is the equivalent of “Get or Create” semantics. If a node with this pattern already exists, it is matched and returned, otherwise a new one is created. These two options are exposed and can be acted on, like the following:

MERGE (keanu:Person { name:'Keanu Reeves' })
ONCREATESET keanu.created = timestamp()
ONMATCHSET keanu.lastSeen = timestamp()
RETURN keanu

Literal Node Patterns

If there are now special conditions to observe, simple property matches can be stated directly in the MATCH clause, making the MATCH statement more readable. For example, matching a simple node with a “name” property can look like this:

MATCH (keanu:Person { name:'Keanu Reeves' })
RETURN keanu

Returning Documents Structures with Literal Maps and Collections

This is a very convenient way to return JSON-documents as results from a Cypher query, making client-side parsing much easier. Any expression (including paths), collections and even nested maps can be used and returned. Here is an example:

MATCH (a:Person { name: "Andres" })<-[:FATHER_OF]-(child)
RETURN a.name as property,
  "literal" as string,
  (a)--() as path,
  [0,1] as collection,
  {name:a.name, kids:collect(child.name), _id:ID(a), _labels:labels(a)} as document

Will return:

Of course the Neo4j Manual has been updated to reflect all the changes and the Cypher Reference card too.

We are extremely excited about this Neo4j release and really want to ask you for your feedback, comments and contributions to our beloved graph database project and and its wonderful community.

Enjoy Neo4j 2.0, and Happy Coding and Happy Holidays!

/peter and the whole Neo4j developer community


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}