openbeerdb.com for Neo4j Graph Database
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cql
.gitignore
README.md
beerers.csv
beers.csv
breweries.csv
categories.csv
geocodes.csv
neo4j-openbeerdb.puml
styles.csv

README.md

neo4j-openbeerdb

GraphQL backend : https://github.com/aicfr/graphql-neo4j-openbeerdb

Android application : https://github.com/Gerth01/graphql-android-openbeer

Inspired by https://neo4j.com/graphgist/beer-amp-breweries-graphgist

Powered by http://openbeerdb.com and https://neo4j.com

Docker

docker run -d -p 7474:7474 -p 7687:7687 -v $(pwd)/neo4j/data:/data -e NEO4J_AUTH=neo4j/openbeerdb neo4j:3.4.0

Schema

openbeerdb

  • Beerer

    • beererID
    • beererName
    • location
    • description
    • website
    • picture
  • Beer

    • beerID
    • beerName
    • description
    • abv : alcohol by volume
    • picture
  • Brewery

    • breweryID
    • breweryName
    • address1
    • city
    • state
    • zipCode
    • country
    • phoneNumber
    • website
    • description
  • Category

    • categoryID
    • categoryName
  • Style

    • styleID
    • styleName
  • Geocode

    • geocodeID
    • location (latitude, longitude)

Create nodes, indexes and relationships

For cql script, view cql\load_openbeerdb.cql. Thanks @rvanbruggen !

Create nodes

LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/aicfr/neo4j-openbeerdb/master/beerers.csv' AS row
CREATE (:Beerer { beererID: toInteger(row.id), beererName: row.name, location: row.location, description: row.descript, website: row.website, picture: row.picture })

LOAD CSV WITH HEADERS FROM 'https://github.com/aicfr/neo4j-openbeerdb/raw/master/beers.csv' AS row
CREATE (:Beer { beerID: toInteger(row.id), beerName: row.name, description: row.descript, abv: toFloat(row.abv) })

LOAD CSV WITH HEADERS FROM 'https://github.com/aicfr/neo4j-openbeerdb/raw/master/breweries.csv' AS row
CREATE (:Brewery { breweryID: toInteger(row.id), breweryName: row.name, address1: row.address1, city: row.city, state: row.state, zipCode: row.code, country: row.country, phoneNumber: row.phone, website: row.website, description: row.descript })

LOAD CSV WITH HEADERS FROM 'https://github.com/aicfr/neo4j-openbeerdb/raw/master/categories.csv' AS row
CREATE (:Category { categoryID: toInteger(row.id), categoryName: row.cat_name })

LOAD CSV WITH HEADERS FROM 'https://github.com/aicfr/neo4j-openbeerdb/raw/master/styles.csv' AS row
CREATE (:Style { styleID: toInteger(row.id), styleName: row.style_name })

LOAD CSV WITH HEADERS FROM 'https://github.com/aicfr/neo4j-openbeerdb/raw/master/geocodes.csv' AS row
CREATE (:Geocode { geocodeID: toInteger(row.id), latitude: toFloat(row.latitude), longitude: toFloat(row.longitude) })

Create indexes

CREATE INDEX ON :Beerer(beererID)
CREATE INDEX ON :Beer(beerID)
CREATE INDEX ON :Brewery(breweryID)
CREATE INDEX ON :Category(categoryID)
CREATE INDEX ON :Style(styleID)
CREATE INDEX ON :Geocode(geocodeID)

Create relationships

MATCH (b1:Beerer {beererID: 1})
MATCH (b2:Beerer {beererID: 6})
CREATE (b1)-[i:IS_FRIEND_OF]->(b2)
SET i.since = '1997-04-22'

MATCH (b1:Beerer {beererID: 3})
MATCH (b2:Beerer {beererID: 6})
CREATE (b1)-[i:IS_FRIEND_OF]->(b2)
SET i.since = '2009-01-20'

MATCH (beerer:Beerer {beererID: 3})
MATCH (beer:Beer {beerID: 4265})
CREATE (beerer)-[r:RATED]->(beer)
SET r.rating = 5,r.comment = '',r.createdAt = timestamp()

MATCH (beerer:Beerer {beererID: 3})
MATCH (beer:Beer {beerID: 4265})
CREATE (beerer)-[c:CHECKED]->(beer)
SET c.location = 'Vineuil, FR',c.price = 4.5,c.createdAt = timestamp()

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://github.com/aicfr/neo4j-openbeerdb/raw/master/beers.csv" AS row
MATCH (beer:Beer {beerID: toInteger(row.id)})
MATCH (brewery:Brewery {breweryID: toInteger(row.brewery_id)})
MERGE (beer)-[:BREWED_AT]->(brewery)

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://github.com/aicfr/neo4j-openbeerdb/raw/master/beers.csv" AS row
MATCH (beer:Beer {beerID: toInteger(row.id)})
MATCH (category:Category {categoryID: toInteger(row.cat_id)})
MERGE (beer)-[:BEER_CATEGORY]->(category)

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://github.com/aicfr/neo4j-openbeerdb/raw/master/beers.csv" AS row
MATCH (beer:Beer {beerID: toInteger(row.id)})
MATCH (style:Style {styleID: toInteger(row.style_id)})
MERGE (beer)-[:BEER_STYLE]->(style)

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://github.com/aicfr/neo4j-openbeerdb/raw/master/geocodes.csv" AS row
MATCH (brewery:Brewery {breweryID: toInteger(row.brewery_id)})
MATCH (geocode:Geocode {geocodeID: toInteger(row.id)})
MERGE (brewery)-[:GEOLOCATED_AT]->(geocode)

// Neo4j 3.4 locations added from Geocode
MATCH (geocode:Geocode)
SET geocode.location = point({latitude: geocode.latitude, longitude: geocode.longitude});

CREATE INDEX ON :Geocode(location)
CREATE INDEX ON :Beer(beerName)
CREATE INDEX ON :Beerer(beererName)
CREATE INDEX ON :Brewery(breweryName)
CREATE INDEX ON :Category(categoryName)
CREATE INDEX ON :Style(styleName)

Queries

For more queries, view cql\query_openbeerdb.cql. Thanks @rvanbruggen !

Beers for a particular category

MATCH (category:Category {categoryName: "German Lager"}) <- [:BEER_CATEGORY]- (beer:Beer)
RETURN DISTINCT(beer.beerName) as beer

Beers for a particular category and brewery location

MATCH (category:Category {categoryName: "British Ale"}) <- [:BEER_CATEGORY]- (beer:Beer) -[:BREWED_AT] -> (brewery:Brewery {country: "United Kingdom"})
RETURN DISTINCT(beer.beerName) as beer

Location : Beers around seattle

WITH point({latitude: 47.608013, longitude: -122.335167}) AS seattle
MATCH path = (geocode:Geocode)--(br:Brewery)--(b:Beer)
WHERE distance(geocode.location, seattle) < 200000
RETURN path

Resources