Cypher Data Model

The Cypher language interacts with data organized in a graph structure, unlike tabular or document-based models. This graph-based model in Cypher consists of Nodes, Relationships, Properties, Labels, and Paths. Understanding these elements is fundamental to working with Cypher in Polypheny.

Nodes

Nodes are the primary entities in the graph. They are the “things” or objects that data is stored about. For example, in a social network, each person could be represented by a node. Nodes are usually represented in Cypher syntax as follows:

(node)

Relationships

Relationships connect nodes and represent how they are associated with each other. For instance, in a social network, a ‘FRIEND_OF’ relationship might exist between two person nodes. Every stored relationship has exactly one type and a direction from its start node to its end node. In a MATCH pattern, you can omit the type to match any type or omit the arrowhead to match either direction. This pattern specifies both the type and the direction.

(node1)-[relationship:FRIEND_OF]->(node2)

Properties

Both nodes and relationships can have properties. Properties are named values that add details or attributes to nodes and relationships. For example, a ‘Person’ node might have ‘name’ and ‘age’ properties. A ‘FRIEND_OF’ relationship might have a ‘since’ property indicating when the friendship started. In Cypher, properties are contained within curly brackets {}:

(person:Person {name: 'John', age: 30})

Read a fixed property with person.name. Use brackets with a string expression to choose the property at runtime, as in person[$key]. Both forms work on nodes and relationships and yield null for a missing property. See how to bind a named parameter.

Graph properties accept scalar values and lists of non-null scalars from one type family. For example, a list can contain strings, or it can mix integers and floating-point numbers. Temporal scalars are also valid properties. A list of temporal properties must contain values of the same kind, such as a list of dates. Empty lists are valid. Maps, nested lists, and lists containing null are query values outside that property format. CREATE omits properties whose value is null, and assigning null in SET removes a property. A map can supply multiple assignments with SET if its individual values meet these rules. See the temporal functions for constructing and reading time values.

An integer computed by Cypher keeps its integer type when stored as a graph property and read back. Use keys() and properties() to inspect the properties of a stored node or relationship.

Labels

Labels categorize nodes. A node can have zero or more labels. For instance, a Person label can identify nodes representing people. In a pattern, prefix each label with a colon (:).

(person:Person)

Use labels in node patterns and predicates. Cypher graph namespaces currently lack support for creating indexes or constraints.

Paths

Paths are sequences of nodes and relationships. Paths can be of any length and are particularly useful when making complex queries. For example, you might want to find a path of ‘FRIEND_OF’ relationships leading from one person to another. In Cypher, a path can be represented as follows:

(startNode)-[relationship*]->(endNode)

Here * matches one or more relationships and binds their ordered list to relationship. Use a named path pattern to capture the nodes as well. Use an explicit zero lower bound when you want to allow a path with no relationships.

Two bindings of the same node or relationship compare equal by identity. Path equality also depends on traversal order, so reversing a path can change the path comparison even though the traversed relationship has the same identity.

Understanding these five key aspects of the Cypher data model is crucial to working with Cypher queries effectively. They form the building blocks for modeling and querying your data in a graph database in Polypheny using the Cypher language.

© Polypheny GmbH. All Rights Reserved.