- Neo4j Graph Data Modeling
- Mahesh Lal
- 420字
- 2021-07-16 13:31:17
Introduction to modeling nodes and relationships
We looked at the data models in Figure 2.2. Without delving into technical details, we can say that "A person can fly from New York to London on carrier X". With this statement, we can start exploring possibilities in which this data can be modelled. A preliminary approach would be to mark cities as nodes and flights as relationships, as shown in the following figure:

Figure 2.3: A preliminary model with flights and cities—the property graph
This might seem to be a fair model, however, there are a few problems with the approach. Relationships, in graphs, are used to model how the entities' nodes are related to each other. As discussed earlier, flights are one of the two core entities in our model. Flights don't relate cities to each other, instead, they are a means to get from one city to another. Modeling flights as relationships, can work out in presenting a flight plan, but if we have to allow flight bookings in the future, then we need to change flights to nodes. In general, it's always a good practice to model any entity in the domain as a node. Figure 2.4 shows us an alternative approach to model flights and cities.
Note
Modeling entities as relationships must be avoided. Relationships in Neo4j can't have other relationships linked to them. Relationships should depict semantically relevant connections between two entities, not entities themselves.

Figure 2.4: A model for flights and cities
The preceding data model has :Flight and :City as labels for the nodes for flights and cities, respectively. :HAS_FLIGHT and :FLYING_TO are relationships that link a flight to its origin city and destination city, respectively.
When we represent a part of a graph that contains all possible nodes and relationships, we lay down a specification for how data is connected and structured. Thus, we can describe graphs using specification by example.
This graph seems to be a good starting point for us to begin feeding the data into Neo4j.
Note
Before we move forward, it would be a good idea to install Neo4j so that we can work on the Cypher queries. Neo4j can be downloaded from http://neo4j.com/download/.
Once installed, we will use the neo4j-shell, a console tool for Neo4j to create nodes and relationships. Further in this book, we will make use of the Neo4j Browser tool, when we start dealing with traversal and exploring our graph. Before trying out any of the queries, ensure that the Neo4j server is started.
- WildFly:New Features
- Drupal 8 Blueprints
- Three.js開發(fā)指南:基于WebGL和HTML5在網(wǎng)頁上渲染3D圖形和動畫(原書第3版)
- 精通Scrapy網(wǎng)絡(luò)爬蟲
- Python高效開發(fā)實戰(zhàn):Django、Tornado、Flask、Twisted(第2版)
- Java EE 7 Development with NetBeans 8
- Android程序設(shè)計基礎(chǔ)
- Python3.5從零開始學(xué)
- Microsoft 365 Certified Fundamentals MS-900 Exam Guide
- C指針原理揭秘:基于底層實現(xiàn)機制
- OpenCV Android Programming By Example
- Android移動應(yīng)用項目化教程
- Visual Basic程序設(shè)計基礎(chǔ)
- Java面試一戰(zhàn)到底(基礎(chǔ)卷)
- HTML5+jQuery Mobile移動應(yīng)用開發(fā)