(I) Download & Install Neo4j
You can download Neo4j to your own laptop
Or download Neo4j to Linux machines in the undergrad lab
Follow the instructions
Windows: Run the installer; Double-click to start.
MacOS & Linux: Open a terminal, Go to the bin folder in Neo4j folder, Start with ./neo4j start
Read Installation and Deployment , if you have any question of installing Neo4j.
(II) Configure Neo4j
After you start the Neo4j Service
Open Neo4j Shell with ./neo4j-shell in bin folder
Open Web Interface with http://localhost:7474
The defaul database is in [neo4j_folder]/data/graph.db directory
The configuration file is [neo4j_folder]/conf/neo4j-server.properties
You can change the database location by modifying org.neo4j.server.database.location=[database directory]
You can also change the ports for the web interface
You had better stop Neo4j before you change the configuration file
The manual of server configuration can be found here
(III) Import Data
Create a directory for importing data
For example: mkdir [neo4j_folder]/data/hubway.db
Stations data: hubway_stations_out.csv
Trips data: hubway_trips_sample_out.csv
a) Go to the bin folder in neo4j folder,
b) Use the following command to import the data:
./neo4j-import --into [Database_Directory] --nodes [Path]/hubway_stations_out.csv --relationships [Path]/hubway_trips_sample_out.csv
c) Change [Database_Directory] to your database directory.
d) Change [Path] to your real path where the data files can be located.
e) Use pwd to check the directory
f) You should be able to see: Imported 142 nodes, 100000 relationships
a) Open the configuration file conf/neo4j-server.properties
b) Change the database location org.neo4j.server.database.location=[Database_Directory]
c) For example: org.neo4j.server.database.location=data/hubway.db
(If you use the directory created in 2) to store the database)
(IV) Cypher Query Language
MATCH (n) RETURN COUNT(*);
MATCH (m)-[r]->(n) RETURN COUNT(*);
Find all stations with names including string 'Boston'
SQL: SELECT * FROM stations WHERE station LIKE '%Boston%';
NoSQL: MATCH (n) WHERE n.name CONTAINS 'Boston' RETURN n;
Read manual here