Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Neo4j Graph Data Modelling

You're reading from   Neo4j Graph Data Modelling Design efficient and flexible databases by optimizing the power of Neo4j

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781784393441
Length 138 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Mahesh K Lal Mahesh K Lal
Author Profile Icon Mahesh K Lal
Mahesh K Lal
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Graphs Are Everywhere FREE CHAPTER 2. Modeling Flights and Cities 3. Formulating an Itinerary 4. Modeling Bookings and Users 5. Refactoring the Data Model 6. Modeling Communication Chains 7. Modeling Access Control 8. Recommendations and Analysis of Historical Data 9. Wrapping Up Index

The property graph model

In Neo4j, we use a property graph model to represent information. The property graph model is an extension of the graphs from mathematics. The following figure gives an example of how data from Figure 1.1 can be represented in Neo4j:

The property graph model

Figure 1.2: Nodes, relationships and properties

The preceding figure introduces the following concepts that we use to model a property graph:

  • Nodes: Entities are modelled as nodes. In Figure 1.2, London, Bob, Alice are all entities.
  • Labels: These are used to represent the role of the node in our domain. A node can have multiple labels at the same time. Apart from adding more meaning to nodes, labels are also used to add constraints and indices that are local to the particular label. In the preceding figure, :Person and :Location are the two labels that we used. We can add an index or constraint on name for each of these labels, which will result in two separate indices—one for :Location and the other for :Person.
  • Relationships: These depict directed, semantically relevant connections between two nodes. A relationship in Neo4j will always have a start node, an end node, and a single type. While relationships need to be created with a direction, we can ignore the direction while traversing them. :LIVES_IN and :IS_MARRIED_TO in Figure 1.2 are relationship types.
  • Properties: These are key-value pairs that contain information about the node or relationship. In the previous figure, name and since are both properties that divulge more information about the node or relationship they are associated with. Neo4j can accept any Java Virtual Machine (JVM) type as a property, including but not limited to, date, string, double, and arrays.

This property graph model allows us to model data as close to the real world as possible.

The resultant model is simpler and more expressive. It also explicitly calls out relationships. In contrast to an RDBMS, which uses foreign keys to imply relationships, having them explicitly defined allows us to retrieve data by traversing relationships to find the information we need. This is a deliberate, practical algorithmic approach that uses the connectedness of data, rather than relying on some index lookups or joins to find the related data. Explicit relationships also make the property graph model a natural fit for most problem domains, as they are interconnected.

You have been reading a chapter from
Neo4j Graph Data Modelling
Published in: Jul 2015
Publisher:
ISBN-13: 9781784393441
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime