Please Note: The Neo4j Server uses Java, AND SPECIFICALLY the Oracle(R) Java(TM) 17, OpenJDK(TM) 17 version - Neo4j does NOT support Java 16.0.1. So, the Oracle version of Java mentioned needs to be installed before Neo4j Server can run. Java can be installed by visiting: http://www.java.com.
Installing Oracle Java JDK 17 on MacOS
We visit https://www.oracle.com/java/technologies/downloads/#java17, download the x64 DMG Installer file, locate it and run it.
Once done installing we can check that Java JDK 17 was properly installed:
java -version
# If everything installed properly we should get:
# java version "17.0.8" 2023-07-18 LTS
# Java(TM) SE Runtime Environment (build 17.0.8+9-LTS-211)
# Java HotSpot(TM) 64-Bit Server VM (build 17.0.8+9-LTS-211, mixed mode, sharing)
Excellent, now we’re ready to install Neo4j on our Mac. https://neo4j.com/docs/operations-manual/current/installation/osx/
Graph Theory 101
There are many problems that can be illustrated by using two fundamental elements: nodes and edges. If we think of two air ports , say JFK in New York and Charles de Gaule in Paris, and the aeroplane route between - then the cities are nodes and the route is an edge. We can expand that analogy to envelope all international airports (all internation airports have a unique id) and all the routes between these.
What we get is a graph model of the international airports and their connections.
Some history: graph theory was invented by Swiss mathematician Leornard Euler. The original example is that of using a graph to model the connections between seven bridges in Eulers hometown of Keuningsberg (St. Petersburg).
Benchmark:
https://github.com/dgraph-io/benchmarks https://github.com/dgraph-io/benchmarks/tree/master/data/neo4j
Step 0: Get Neo4j
Things change, but at the time of writing I navigated to https://neo4j.com/pricing/, clicked on Self-Managed and then Download for Free.
Since I’m on a Mac I downloaded the Neo4j Community Edition 5.10.0
Linux / Mac Executable Neo4j 5.10.0 (tar) version Credentials username=‘neo4j’ and password=‘neo4j’. having downloaded the file
cd $HOME
# We create a permanent folder that will hold our Neo4j server, and cd into it.
mkdir NEO4J_HOME
cd NEO4J_HOME
# We get the neo4j community edition, and then upack it.
# (we use flag -L to instruct curl to follow redirects, and flag -k since it https)
curl -L -k https://neo4j.com/artifact.php\?name\=neo4j-community-5.10.0-unix.tar.gz | tar -xv
# Next (in the same NEO4J_HOME folder) we:
# 1. Accept the evaluation license:
# ./neo4j-community-5.10.0/bin/neo4j-admin server license --accept-evaluation
# > If you are using Community Edition, you can skip this step.
# 2. We test that we can launch the Neo4j console application:
./neo4j-community-5.10.0/bin/neo4j console
# If we get the following output in the terminal, it means we're almost there:
# Directories in use:
# ... lots of output removed for brevity ...
# Starting Neo4j.
# 2023-07-29 19:48:23.987+0000 INFO Starting...
# 2023-07-29 19:48:26.220+0000 INFO This instance is ServerId{e657df02} (e657df02-c90a-41d8-a524-2b3bd20b3b42)
# 2023-07-29 19:48:28.680+0000 INFO ======== Neo4j 5.10.0 ========
# 2023-07-29 19:48:34.510+0000 INFO Bolt enabled on localhost:7687.
# 2023-07-29 19:48:37.880+0000 INFO Remote interface available at http://localhost:7474/
# 2023-07-29 19:48:37.889+0000 INFO id: 2D22220B748D4CEB34A4C7012CB27B45CC88EFC838B5A162F43C0BCE3B368F7C
# 2023-07-29 19:48:37.891+0000 INFO name: system
# 2023-07-29 19:48:37.892+0000 INFO creationDate: 2023-07-29T19:48:31.227Z
# 2023-07-29 19:48:37.892+0000 INFO Started.
Yay! Neo4j Server running.
Neo4j Daemon - optionally, we can also run Neo4j as a background process. To do this:
./bin/neo4j start
Step: Connect to Neo4j using the browser
We can connect to the Neo4j Server and open an admin dashboard by using a brower. The first thing that will happen is that Neo4j will ask us to change the default username: ’neo4j’ and the default password: ’neo4j’.
So, let’s check that the Neo4j server is working, by browsing to http://localhost:7474, or from a terminal on MacOS:
open http://localhost:7474
For additional commands see the Unix tarball installation documentation.
https://neo4j.com/download-center/?ref=subscription#community
Default login is username ’neo4j’ and password ’neo4j’
Step 3:
Once you create a new password for the ’neo4j’ user upon visiting the Neo4j Browser the first time, you’ll have full access to the Neo4j database.
The Neo4j Browser is a tool for developers to explore their Neo4j database, execute Cypher queries and see results in tabular or graph form. You can even use the Browser to:
- Import data
- Call user-defined procedures in Java
- Profile queries, looking at the execution plan with EXPLAIN and PROFILE.
Step 4: Explore Sample Datasets
Explore two sample datasets built into the Neo4j Browser using the following commands: :play movie graph :play northwind graph Both datasets are easily accessible using the blue “Write Code” button under the “Jump into Code” section of the guides.
Neo4j is used by developers building applications for a wide range of use cases and industries. Graph databases are a great fit for any use case where a relationship-first approach is helpful, including content recommendations, network/IT analysis, fraud detection, Internet of Things(IoT) and more.
Step 5: interact with Neo4j using Rust
The Neo4j Browser is our developer interface to the Neo4j graph database. However, to write applications we want to interact with Neo4j using our favorite programming language (well, Rust). https://neo4j.com/docs/driver-manual/1.7/#driver-get-the-driver
From what I can tell, at the time of writing this (see post date), Neo4j offers language binding for the following languages: Java, .NET, JS, Python, and Go. Not Rust.
To do that we:
Step 6: Create Data Models
We’ll start by creating a very small Data model in order to get going. The core elements that we’ll work with are
Start with a small data model and then build out from there - Neo4j is naturally adaptive, so you can add new node labels,
relationships and properties
on the fly.
Example Data Models
The developer community has provided example data models and queries for a variety of use cases. There are available here: https://neo4j.com/graphgists
Data Import
If we have existing data, for example in CSV format, then we want to experiment with then we can load it into Neo4j using it’s language some existing data you’d like to import? You can import your data from CSV files using the Cypher’s LOAD CSV command. https://neo4j.com/developer/guide-import-csv/ https://neo4j.com/docs/developer-manual/3.0/cypher/#query-load-csv https://neo4j.com/developer/guide-import-csv/ Learn more about import in the Neo4j Developer Manual: Load CSV and Importing CSV Data into Neo4j.
Data intgration - can we mix Postgres and Neo4j?: https://neo4j.com/developer/integration/
Of course, Neo4j believes in polyglot persistence as well - so we’re happy if Neo4j is just one part of your overall architecture and storing your connected data, while your columnar, tabular and document data is stored elsewhere. Learn more about the various types of data integrations possible with Neo4j.
“https://neo4j.com/download-thanks/?edition=community&release=5.10.0&flavour=unix&_gl=11cy7123_gaNTExMDI2NDUxLjE2OTA2NTIwMzI._ga_DL38Q8KGQC*MTY5MDY1MjAzMC4xLjEuMTY5MDY1MjEzMi42MC4wLjA.#install”
Neo4j
Step 1: spin up a free instance of AuroDB
I’m using the AuraDB Free tier.
The next option is the AuraDB Professional plan, which costs $65/month at the time of writing.
According to Neo4j, the database is hosted somewhere in the region of Belgium. Neo4j version 5
Constraints Nodes: 200,000 Relationships: 400,000 RAM: 1 Gb Host: GCP
neo4rs
I’m using Neo4j’s own Rust library neo4rs to interact with the Auro instance.
Neo4j driver for rust - This driver is compatible with Neo4j version 5.x and 4.4.
To try and quickly get started I’ll simply follow the example given on the github page and see how it goes. https://github.com/neo4j-labs/neo4rs#example
Having spun up the AuroDB instance we’ve presented with a very nice looking window
presenting our credentials that I
need in order to connect to the database.
Step : Look at the sample database bundled with Neo4j
From what I can tell, the Neo4j Community Edition 5.10.0 comes bundled with a
small graph movie database example project that we can use to start experimenting right away.
“The front-end page is the same for all drivers: movie search, movie details, and a graph visualization of actors and movies.”
There more information about the example datasets here https://neo4j.com/docs/getting-started/appendix/example-data/
Nice! Next, how do we connect to our database?
Step : Connect to Neo4j Server running on localhost
I’m using https://neo4j.com/docs/getting-started/languages-guides/neo4j-go/ a guide on how to connect to Neo4j from Go - but I’ll try to connect from Rust instead. Let’s g…Rust.
According to Crates.io neo4rs supports
Neo4rs is a Neo4j rust driver implemented using bolt specification This driver is compatible with Neo4j version 5.x and 4.4. Only the latest 5.x version is supported, following the Neo4j Version support policy.
# We start by creating a new Rust project.
cargo new lrn_neo4j
cd lrn_neo4j
# Add the neo4rs dependency.
cargo add neo4rs
# Build the project to pull in all deps and make sure it builds without errors.
cargo build
At the time of writing,
neo4rsis at version 0.6.2.
In a computer system we need an adaptor program in order to make a connection our database, just like we do when we want to connect our computer to a printer - the computer needs to know details about the specific computer in order to interface with it. For each diffrent model/make of printer, we need a particular driver.
It’s the same thing with databases. The database driver functions like an adaptor which connects a generic interface to a specific database vendor implementation. Neo4j provides drivers which allow us to connect to the Neojs database and develop applications which create, read, update, and delete information from the graph db.
Neo4j provides an officially supported driver written in Go (there are also drivers
written in Java, Javascript, .NET, and Python).
The Go driver uses a protocol called Bolt to connect to the Neo4j database.
We are going to use the database driver neo4rs, which is developed by Neo4j but still under active development.