10. Getting started with Neo4j

Mansi Khatri
5 min readSep 13, 2021
Neo4j is a graph data structure

What is Neo4j?

To handle a growing volume of connected data, you can go for Neo4j, a non-relational graph database that’s optimized for managing relationships. The Neo4j database can help you build high-performance and scalable applications that use large volumes of connected data.

Why Neo4j?

Relational databases have several substantial drawbacks:

  1. Volume limitations
  2. Velocity
  3. Lack of relationships
  4. Variety, Scalability

To overcome these limitations, a number of different non-relational databases have been created. Most of them lack relationships, Unlike all other data storage and management technologies, graph databases are focused on relationships and store already connected data. That’s why graph databases prove the most efficient for handling large amounts of connected data.

Neo4j as a graph database

Graph databases are based on graph theory from mathematics. Graphs are structures that contain vertices (which represent entities, such as people or things) and edges (which represent connections between vertices). Edges can have numerical values called weight.

Neo4j provides its own implementation of graph theory concepts. Let’s take an in-depth look at the Labeled Property Graph Model in the Neo4j database. It has the following components:

  • Nodes (equivalent to vertices in graph theory). These are the main data elements that are interconnected through relationships. A node can have one or more labels (that describe its role) and properties (i.e. attributes).
  • Relationships (equivalent to edges in graph theory). A relationship connects two nodes that, in turn, can have multiple relationships. Relationships can have one or more properties.
  • Labels. These are used to group nodes, and each node can be assigned multiple labels. Labels are indexed to speed up finding nodes in a graph.
  • Properties. These are attributes of both nodes and relationships. Neo4j allows for storing data as key-value pairs, which means properties can have any value (string, number, or boolean).

The graph data structure might seem unusual, but it’s simple and natural. Here’s an example of a simple graph data model in Neo4j:

As you can see, this graph contains two nodes (Alice and Bob) that are connected by relationships. Both nodes share the same label, Person. In the graph, only Bob’s node has properties, but in Neo4j every node and relationship can have properties.

A graph model is intuitive and easy for people to interpret. After all, the human brain doesn’t think in terms of tables and rows but in terms of abstract objects and connections. In fact, anything you can draw on a blackboard can be displayed with a graph.

First download and install Neo4j and then run the server in localhost.

Here, by using get some data 2 nodes are created and one relation called says is created using the query.

In the below image you can see the table view of nodes and relations.

After that load, the movie database to the neo4j and it will show the data in graph format.

By using different query we can find the appropriate information like how many entries are there or the total number of relationships

In this database, There are 9 person nodes and 8 movies nodes, and a total of 18 relationships between nodes. By using this query we can know that how the person is connected to the movie, who is a producer of the movie, which role the person acted in the movie.

List of relation types that are present in a given database

Here is the list of movies released between 1990and 1995,

Neo4j database use cases

  1. Fraud detection and analytics
  2. Network and database infrastructure monitoring
  3. Recommendation engines
  4. Social networks
  5. Knowledge graph
  6. Identity and access management
  7. Privacy and risk compliance

Gephi tool

Gephi is open-source software for visualizing and analyzing large networks graphs. Gephi uses a 3D render engine to display graphs in real-time and speed up the exploration. You can use it to explore, analyze, spatialize, filter, cluterize, manipulate and export all types of graphs.

So after downloading and installing, we will use the dataset from the gephi website and we will import it into our workspace.

Here are some of the graphical layouts like random, expansion, and force atlas.

So these were some basic operation in the Gephi tool.

That’s all for now… 🥱

--

--