This chapter will introduce more details on the data model and behavior of Neo4j.
Relationships between nodes are a key part of a graph database. They allow for finding related data.
A relationship connects two nodes, and is guaranteed to have valid start and end nodes.
As relationships are always directed, they can be viewed as outgoing or incoming relative to a node, which is useful when traversing the graph:
Relationships are equally well traversed in either direction. This means that there is no need to add duplicate relationships in the opposite direction (with regard to traversal or performance).
While relationships always have a direction, you can ignore the direction where it is not useful in your application.
Note that a node can have relationships to itself as well:
To further enhance graph traversal all relationships have a relationship type. The following example shows a simple social network with two relationship types.
Table 11.1. Using relationship direction and type
What | How |
---|---|
get who a person follows | outgoing |
get the followers of a person | incoming |
get who a person blocks | outgoing |
get who a person is blocked by | incoming |
This example is a simple model of a file system, which includes symbolic links:
Depending on what you are looking for, you will use the direction and type of relationships during traversal.
What | How |
---|---|
get the full path of a file | incoming |
get all paths for a file | incoming |
get all files in a directory | outgoing |
get all files in a directory, excluding symbolic links | outgoing |
get all files in a directory, recursively | outgoing |
Properties are key-value pairs where the key is a string.
Property values can be either a primitive or an array of one primitive type.
For example String
, int
and int[]
values are valid for properties.
Note | |
---|---|
|
Table 11.2. Property value types
Type | Description | Value range |
---|---|---|
|
| |
| 8-bit integer |
|
| 16-bit integer |
|
| 32-bit integer |
|
| 64-bit integer |
|
| 32-bit IEEE 754 floating-point number | |
| 64-bit IEEE 754 floating-point number | |
| 16-bit unsigned integers representing Unicode characters |
|
| sequence of Unicode characters |
For further details on float/double values, see Java Language Specification.
Copyright © 2011 Neo Technology