Neo4j Blog

Fun with Beer – and Graphs

I think it is one of the finest and nicest professions in the world, and I love what I do. I love it specifically, because I get to sell great, awesome, fantastic products really – and I get to work with fantastic people along the way. But the point is I am not a technical person – at all.

However, I do have a passion for technology, and I feel the urge to understand and taste the products that I sell. And that’s exactly what happened when I joined Neo Technology, the makers and maintainers of the popular Neo4j open source graph database.

So I decided to get my hands dirty and dive in head first and also have some fun along the way.

The fun part comes from something that I thoroughly enjoy: Belgian beer. Some of you may know that Stella Artois, Hoegaerden, Leffe and the likes come from Belgium, but few of you know that this tiny little country in the lowlands around Brussels actually produces several thousand beers.

You can read about it on the Wikipedia page: Belgian beers are good and numerous. So how would I go about putting Belgian beers into Neo4j? Interesting challenge.

Part 1: Getting Beer into Neo4j

First, I started with the data source.

The Wikipedia page actually has a full listing of all Belgian beers, and it also includes the brewery, beer type and alcohol percentage – perfect! I can already see a graph emerging.

But how to get it into Neo4j, without doing any programming?

Well, turns out that it was not that difficult…

Read on, or watch this video:

The next step was to “clean” the Wikipedia data and structure it. I used a Google spreadsheet for this – I was actually amazed at its power and ease of use.

Then after some more manipulation and spreadsheet wizardry, I managed to come up with two, very simple files: one for the nodes (the BeerBrands, the AlcoholPercentages, the BeerTypes and the Breweries) and one for the relationships (a Beerbrand “has a” Alcoholpercentage, “is a” specific beertype and a Brewery “brews” a specific Beerbrand).

So then, I had to get these CSV files into a graph and into a graph database (that is, Neo4j). I tried a number of things but ended up going for a very simple tool called Gephi.

The tool has a visualisation component and an analysis/processing component, but I was most interested in the Data Laboratory. This allowed me to import the CSV files above with two clicks and to create a wonderful visualisation immediately.

Well, it turns out there is a Gephi Neo4j plugin available that does exactly that. Just install the plugin, export the Gephi project, and it will generate the Neo4j store files that you can copy over to your graph.db directory.

And now my Neo4j database is up and running. And remember: NO PROGRAMMING INVOLVED. Love that.

To be honest, there was one tiny little hiccup at this point. Because to use the graph in a meaningful way, you really need to have indexes.

Neo4j ships with Lucene for indexing of nodes, relationships and properties, and there is an auto-indexing capability in the product – but that only kicks in AFTER you start adding data to the database.

So the initial import into the database is not indexed. Crap.

Luckily, I have some very bright colleagues at Neo Technology, who have written some nifty utilities that do something about this. And that’s what I did: used the utility, repopulated the autoindex, and there we were. A bit hairy, but NO PROGRAMMING 🙂

Part 2 – Getting Beer out of Neo4j

In the second part, I explore the beer graph visually via the Neo4j Web-interface and some nifty Cypher queries. So, enjoy the video and see the details below:

For example: let’s try to find all Belgian Trappist beers, based on one Trappist beer that I know and love, Orval.

I was able to include a real, ACID-compliant transaction on the graph – adding a “Rik” node to the graph and adding two “loves” relationship, one for Duvel and one for Orval.

It was really interesting to see how Neo4j does the commit/rollback, and how it isolates these updates from the rest of the users. You can test that really easily by having two “clients” talk to the database, and executing the transaction in one client – but querying it from the other.

All in all this was a fantastic and a very educational experience for me. Neo4j is a great tool for many database problems – beer-related or other – and it was really fun to learn how to piece things together and get it to a functioning database, all WITHOUT PROGRAMMING.

About the Author

Rik Van Bruggen, Regional VP & Neo4j Advocate

Rik Van Bruggen brings 10 years experience in sales, specifically in web-based application development and security/identity management to his work at Neo Technology. Previously with Courion and Imprivata, Rik has managed sales and strived for customer success across Europe. Rik is a Belgian technology addict with a passion for sales, family, friends, music, travel, and of course, good food and even better, beer. Rik also runs the Graphistania podcast on graph databases.

11 Comments

Yes, really its nice post, thanks for posting on <a href="http://www.bringerexport.com/&quot; rel="nofollow">energy drinks Import</a>. I just tried this one for the first time the other day and I thought it was pretty good. I love that new cap though fuckin genius man. “<a href="http://www.bringerexport.com/&quot; rel="nofollow">energy drinks</a>” Love the reviews!

Hello, I followed the instructions in the tutorial and I find errors;<br />1. – BeerRelationships.csv file should change the title, start, end by source, target for the Gephi can import<br />2. – When you import the file, in the Edges tab, I have the following:<br />Source<br />1-null<br />2-null<br />…<br />Target<br />100000-null<br />10000-null<br /><br />There is no relationship between the

Hello,<br /><br />I agree with Marco Guado. When i completely copied graph.db folder, no problem occured. But when i worked with the .csv files, i run into some problems. first of all, BeerRelationships.csv file didn&#39;t work with &quot;start&quot; and &quot;stop&quot; title. althought i renamed them with &quot;source&quot; and &quot;target&quot;, it nevertheless didn&#39;t work out. also when

Hello<br />The right way to import csv files in Gephi, is changing the header;<br />BeerNodes.csv = id,label,type<br />BeerRelationsShips.csv = source,target,label<br /><br />for export of Neo4j Gephi to make the relationship by label and write the first relation: HasAlcoholPercentaje, then open the Web console and visualize the nodes 7474, Okey.

Hello right way to import csv files in Gephi is changing the heading; BeerNodes.csv = id, label, type, BeerRelationsShips.csv = source, traget, label.<br />for export of Neo4j Gephi to make the relationship by label and write the first relation: HasAlcoholPercentaje, then open the Web console and visualize the nodes 7474, Okey.

Very interesting! How do you get the graph representation with the following query ? START duvel=node:node_auto_index(name=”Duvel”), orval=node:node_auto_index(name=”Orval”) MATCH p = AllshortestPaths( duvel-[*]-orval ) return p;

[…] and yields a delicious selection of many flavours of beers. Following our own tradition started by Rik van Bruggens beer-graph we wanted to pay homage to Oregons microbreweries. We white boarded a simple graph-data-model and […]

This website uses 'cookies' to give you the best, most relevant experience. Using this website means you’re OK with this. You can change which cookies are set at any time - by clicking on more info. Accept