NoSQL Zone is brought to you in partnership with:

Max De Marzi, is a seasoned web developer. He started building websites in 1996 and has worked with Ruby on Rails since 2006. The web forced Max to wear many hats and master a wide range of technologies. He can be a system admin, database developer, graphic designer, back-end engineer and data scientist in the course of one afternoon. Max is a graph database enthusiast. He built the Neography Ruby Gem, a rest api wrapper to the Neo4j Graph Database. He is addicted to learning new things, loves a challenge and finding pragmatic solutions. Max is very easy to work with, focuses under pressure and has the patience of a rock. Max is a DZone MVB and is not an employee of DZone and has posted 57 posts at DZone. You can read more from them at their website. View Full User Profile

Neo4j 2.0 is Coming

06.27.2013
| 2176 views |
  • submit to reddit


neoiscoming

House Neo4j of Graph Databases is one of the Great Houses of NOSQL and the principal noble house of The Graph; many lesser houses are sworn to them. In days of old they ruled as Kings of the Graph; since the Aggregate Store Conquest they have been Wardens of the Path. Their seat, San Mateo, is an ancient castle renowned for its sushi. Their sigil is a octopus racing across a field of white, and their words are “Neo4j 2.0 Is Coming,” one of only a few house mottoes to be a warning rather than a boast. Members of the family tend to be lean of build and long of face, with golden hair and blue eyes.

Whoa… sorry, getting carried away there… but Neo4j 2.0 brings with it some great new functionality. Take a look at the following presentation by Andreas Kolleger.

Whoa… sorry, getting carried away there… but Neo4j 2.0 brings with it some great new functionality. Take a look at the following presentation by Andreas Kolleger.

With it come the Cypher MERGE functionality and a Transactional REST Endpoint starting with Milestone 3, as well as Node Labels and Schema Indexes since the first release.

I wanted to play with the new functionality and see what kind of niceties it affords us. I’m using a sample dataset related to the Movie Industry (Movies, Actors, Directors, etc.) that looks like:

CREATE (TheMatrix {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (Keanu {name:'Keanu Reeves', born:1964})
CREATE (Carrie {name:'Carrie-Anne Moss', born:1967})
CREATE (Laurence {name:'Laurence Fishburne', born:1961})
CREATE (Hugo {name:'Hugo Weaving', born:1960})
CREATE (AndyW {name:'Andy Wachowski', born:1967})
CREATE (LanaW {name:'Lana Wachowski', born:1965})
CREATE (JoelS {name:'Joel Silver', born:1952})
CREATE
  (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
  (Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
  (Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
  (Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
  (AndyW)-[:DIRECTED]->(TheMatrix),
  (LanaW)-[:DIRECTED]->(TheMatrix),
  (JoelS)-[:PRODUCED]->(TheMatrix)....

This data is how you’d create data normally in Neo4j 1.9. To update it to 2.0 and make use of Labels and Indexes, we just need to update it slightly. Looking at our graph, we can see we have nodes that represent Actors, Directors, Movies, Writers, etc. Each one of these also has a primary way of being found in the graph, names for various types of people, and titles for Movies. So we’ll create Indexes on these properties for their individual Labels:

CREATE INDEX ON :Actor(name);
CREATE INDEX ON :Director(name);
CREATE INDEX ON :Writer(name);
CREATE INDEX ON :Producer(name);
CREATE INDEX ON :Movie(title);
....

Then we’ll MATCH the nodes in the graph that should have those labels, and set them. For example, every node that has a “title” property is a Movie, and every node that has an outgoing “ACTED_IN” relationship is an Actor.

MATCH node
WHERE has(node.title)
SET node:Movie;
 
MATCH node
WHERE (node)-[:ACTED_IN]->()
SET node:Actor;
...

Yeah, it’s really that easy. Some folks have asked for a “Migration Tool”, but the reality is that a little Cypher does all the work for us.

One of the new REST Endpoints available to us in Neo4j 2.0 allows us to get a list of all the labels. This has been included inNeography as the “list_labels” method. We can use this Metadata to probe the graph and build an interface that doesn’t require much coding or configuration.

I’m going to combine VisualSearch.js and VivaGraph.js to make this happen.

Here is a sneak peak at what it looks like… a blog post on it is forthcoming.

screenshot


Published at DZone with permission of Max De Marzi, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)