Category Archives: Cypher

Importing the Hacker News Interest Graph


Graphs are everywhere. Think about the computer networks that allow you to read this sentence, the road or train networks that get you to work, the social network that surrounds you and the interest graph that holds your attention. Everywhere you look, graphs. If you manage to look somewhere and you don’t see a graph, then you may be looking at an opportunity to build one. Today we are going to do just that. We are going to make use of the new Neo4j Import tool to build a graph of the things that interest Hacker News.
Continue reading

Tagged , , , , , , , , , , , ,

Triggers in Neo4j


One of the often overlooked features in Neo4j is the “TransactionEventHandler” capabilities… better known in the database world as “Triggers“. When a transaction occurs, we can analyze that event and decide to take some action. To accomplish this, we’ll write a “Kernel Extension” ( a little different from the Unmanaged Extensions we’ve seen on this blog ) to tie in our trigger.

Continue reading

Tagged , , , , , ,

One Direction Relationships in Neo4j


In the Neo4j Property Graph model, every single Relationship must be Typed and Directed. This means they must have a specific name (FRIENDS, LIKES, FOLLOWS, etc) and have a Start Node and an End Node to show direction. What’s neat is that when you write your queries you can choose to ignore that. The following queries are all valid:

// Get all the people I follow 
MATCH (u1:Person)-[:FOLLOWS]->(u2:Person)
WHERE u1.username = "maxdemarzi"
RETURN u2.username

// Get all the people that I follow or follow me
MATCH (u1:Person)-[:FOLLOWS]-(u2:Person)
WHERE u1.username = "maxdemarzi"
RETURN u2.username

// Get all the people related to me 
MATCH (u1:Person)--(u2:Person)
WHERE u1.username = "maxdemarzi"
RETURN u2.username

Continue reading

Tagged , , , , ,

Giving Neo4j 2.2 a Workout


Neo4j 2.2 is getting released any day now, so let’s put the Release Candidate through its paces with Gatling. Once we download and start it up, you’ll notice it wants us to authenticate.
Continue reading

Tagged , , , , , , , ,

Tracking User Paths in an IVR with Neo4j

I started my software development career writing applications for a Call Center at a small bank in Florida. I remember the bank had purchased whatever the “Cadillac” of Interactive Voice Response (IVR) systems was then for some crazy amount of money. Today you can build an IVR overnight using Twilio.


When you sign up with Twilio, you get to choose your phone number (more or less). For example, I picked +1 (636) 451-7411, which spells out +1 (neo) 4j1-7411. If you were to call this number right now (assuming I have not run out of Twilio credits) you’ll connect to my IVR.
Continue reading

Tagged , , , , ,

Translating Cypher To Neo4j Java API 2.0


About 6 months ago we looked at how to translate a few lines of Cypher in to way too much Java code in version 1.9.x. Since then Cypher has changed and I suck a little less at Java, so I wanted to share a few different ways to translate one into the other just in case you stuck in a mid-eighties time warp and are paid by the number of lines of code you write per hour.

But first, lemme take a #Selfie let’s make some data. Michael Hunger has a series of blog posts on getting and creating data in Neo4j, we’ll steal borrow his ideas. Let’s create 100k nodes:

WITH ["Jennifer","Michelle","Tanya","Julie","Christie","Sophie","Amanda","Khloe","Sarah","Kaylee"] AS names 
FOREACH (r IN range(0,100000) | CREATE (:User {username:names[r % size(names)]+r}))

Continue reading

Tagged , , , , , , , , , , ,

Caching Partial Traversals in Neo4j


Sometimes you’ll find yourself looking at a traversal and thinking… “I’m going to be doing this one thing over and over again.” That sounds kind of wasteful and years of recycling have taught us not to be wasteful. Let’s take a look at an example from our past. Look back at the Neo Love application, the one with the picture of Marilyn Monroe and Groucho Marx. Let’s see what a Neo4j 2.0 version of that query would look like:

Continue reading

Tagged , , , , , , , ,

Neo4j Spatial Part 2


In part 1 of this series we looked at how to get started with Neo4j Spatial and we looked at some of the pieces we’ll use today to build a proof of concept application. I’m calling the application “Nom Nom Nom” in reference to its onomatopoeic meme.

So we’ll get data from Factual, get data from OpenTable, combine them and import them into Neo4j:

Continue reading

Tagged , , , ,

Neo4j Spatial Part 1

One of my new year resolutions is to do a project with Neo4j Spatial, so we’ll kick off my first blog post of the year with a gentle introduction to this awesome plugin. I advise you to watch this very short 15 minute video by Neo4j Spatial creator Craig Taverner. The man is a genius level developer, you’ll gain IQ points just listening, I swear.

The plan is to make a Restaurant Recommendation engine based on things you care about and your current location. Yes, this is baby level stuff, but we’ll start with this and see where else Neo4j Spatial can take us later on.
Continue reading

Tagged , , , , , , ,

Translating Cypher to Java


The expressive power of Cypher is already awesome and getting better with the Neo4j 2.0 release. Let’s take a step back from the bleeding edge and see Cypher in 1.9.4 and how it can be translated into Java. First a simple example where we look up a User node by an index and return a list of usernames belonging to the people who are that user’s friends:

START me = node:Users(username='maxdemarzi')
MATCH me -[:FRIENDS]-> people
RETURN people.username

The Cypher statement expresses what I want even better than my botched explanation in English. So how would we do this in the Neo4j Java API?
Continue reading

Tagged , , , , ,

Get every new post delivered to your Inbox.

Join 2,146 other followers