neo4j-com-docs-cypher-cheat-sheet-5-all-...
neo4j-com-docs-cypher-cheat-sheet-5-all-...
OPTIONAL MATCH
Return a node.
MATCH (p:Person {name:
RETURN 'Keanu Reeves'})
RETURN p
Return relationship types.
MATCH (p:Person {name: 'Keanu
Reeves'})-[r:ACTED_IN]->(m)
RETURN type(r)
Delete a relationship.
MATCH (n:Label)-[r]->
DELETE (m:Label)
WHERE r.id = 123
DELETE r
Patterns
Fixed-length patterns
Variable-length patterns
point.distance(b.location,
ndl.location))+ (ndl)
RETURN reduce(acc = 0, r in
relationships(p) | round(acc +
r.distance, 2))
AS distance
Shortest paths
Non-linear patterns
Clauses
CALL procedure
FOREACH
LOAD CSV
Import artists name and year information from a remote file URL.
ORDER BY
SHOW FUNCTIONS
SHOW TRANSACTIONS
TERMINATE TRANSACTIONS
Subqueries
A CALL subquery is executed
UNWIND [0, 1, 2] AS x
CALL () {
once for each row. In this
CALL RETURN 'hello' AS example, the CALL subquery
innerReturn
} executes three times.
RETURN innerReturn
General
Operators
General
DISTINCT, ., []
Mathematical
+, -, *, /, %, ^
Comparison
=, <>, <, >, <=, >=, IS NULL, IS
NOT NULL
Boolean
AND, OR, XOR, NOT
String
+
List
+, IN, [x], [x .. y]
Regular expression
=~
String matching
STARTS WITH, ENDS WITH, CONTAINS
Properties
Predicates
Use functions.
toString(n.property) = $value
List Expressions
Expressions
CASE expressions
Label expressions
Functions
Aggregating functions
Database functions
The db.nameFromElementId
WITH "2:efc7577d-022a-107c-a736-
dbcdfc189c03:0" AS eid
function returns the name of a
RETURN db.nameFromElementId(eid) database to which the element id
AS name
belongs. The name of the database
can only be returned if the provided
element id belongs to a standard
database in the DBMS.
Duration functions
Graph functions
The graph.propertiesByName
UNWIND graph.names() AS name
RETURN name,
function returns a map containing
graph.propertiesByName(name) AS the properties associated with the
props
given graph. The properties are set
on the alias that adds the graph as a
constituent of a composite database.
It is only supported on composite
databases.
List functions
Predicate functions
Scalar functions
String functions
Spatial functions
Temporal functions
The datetime.transaction
RETURN datetime.transaction() AS
currentDateTime
function returns the current ZONED
DATETIME value using the
transaction clock. This value will
be the same for each invocation
within the same transaction.
However, a different value may be
produced for different transactions.
The localdatetime.transaction
RETURN localdatetime.transaction()
AS now
function returns the current LOCAL
DATETIME value using the
transaction clock. This value will
be the same for each invocation
within the same transaction.
However, a different value may be
produced for different transactions.
The localdatetime.statement
RETURN localdatetime.statement()
AS now
function returns the current LOCAL
DATETIME value using the
statement clock. This value will be
the same for each invocation within
the same statement. However, a
different value may be produced for
different statements within the same
transaction.
The localdatetime.realtime
RETURN localdatetime.realtime() AS
now
function returns the current LOCAL
DATETIME value using the
realtime clock. This value will be
the live clock of the system.
The localtime.transaction
RETURN
localdatetime({
function returns the current LOCAL
year: 1984, month: 10, day: TIME value using the transaction
11,
hour: 12, minute: 31, second: clock. This value will be the same for
14, millisecond: 123, microsecond: each invocation within the same
456, nanosecond: 789
}) AS theDate transaction. However, a different
value may be produced for different
transactions.
The localtime.statement
RETURN
localdatetime({
function returns the current LOCAL
year: 1984, quarter: 3, TIME value using the statement
dayOfQuarter: 45,
hour: 12, minute: 31, second: clock. This value will be the same for
14, nanosecond: 645876123 each invocation within the same
}) AS theDate
statement. However, a different value
may be produced for different
statements within the same
transaction.
localtime.truncate('millisecond',
Vector functions
The
MATCH (n:Label)
WITH n,
vector.similarity.euclidean
vector.similarity.euclidean($query, function returns a FLOAT
n.vector) AS score
RETURN n, score representing the similarity between
the argument vectors based on their
Euclidean distance.
The vector.similarity.cosine
MATCH (n:Label)
WITH n,
function returns a FLOAT
vector.similarity.cosine($query, representing the similarity between
n.vector) AS score
RETURN n, score the argument vectors based on their
cosine.
Schema
Search-performance indexes
Cypher includes four search-performance indexes: range (default), text, point,
and token lookup.
Create a range index with the name index_name on nodes with label
Person and property name .
It is possible to omit the index_name , if not specified the index name will be
decided by the DBMS. Best practice is to always specify a sensible name
when creating an index.
The create syntax is CREATE
[RANGE|TEXT|POINT|LOOKUP|FULLTEXT|VECTOR] INDEX …. Defaults to
range if not explicitly stated.
Full-text indexes
CALL db.index.fulltext.queryRelationships("relationship_fulltext_index",
"Alice") YIELD relationship, score
Constraints
List all constraints, returns only the
SHOW ALL CONSTRAINTS
default outputs ( id , name , type ,
entityType , labelsOrTypes ,
properties , ownedIndex , and
propertyType ). Can also be filtered
on NODE UNIQUENESS ,
RELATIONSHIP UNIQUENESS ,
UNIQUENESS , NODE EXISTENCE ,
RELATIONSHIP EXISTENCE ,
EXISTENCE , NODE PROPERTY TYPE ,
RELATIONSHIP PROPERTY TYPE ,
PROPERTY TYPE , NODE KEY ,
RELATIONSHIP KEY , and KEY . For
more information, see Constraints →
Syntax → SHOW CONSTRAINTS.
Performance
Performance
Use parameters instead of literals when possible. This allows Neo4j DBMS
to cache your queries instead of having to parse and build new execution
plans.
Always set an upper limit for your variable length patterns. It is possible to
have a query go wild and touch all nodes in a graph by mistake.
Return only the data you need. Avoid returning whole nodes and
relationships; instead, pick the data you need and return only that.
Use PROFILE / EXPLAIN to analyze the performance of your queries. See
Query Tuning for more information on these and other topics, such as
planner hints.
Database Management
DATABASE Management
ALIAS Management
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
Access Control
USER Management
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
ROLE Management
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
Delete a role.
DROP ROLE role_name
Rename a role.
RENAME ROLE role_name TO
other_role_name
SHOW Privileges
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
Load Privileges
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
ON GRAPH
ON GRAPH Read Privileges
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
ON DATABASE
ON DATABASE Privileges
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
ON DBMS
ON DBMS Privileges
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
AuraDB Business Critical AuraDB Virtual Dedicated Cloud Neo4j Enterprise Edition
Neo4j®, Neo Technology®, Cypher®, Neo4j® Bloom™ and Neo4j® Aura™ are registered
trademarks of Neo4j, Inc. All other marks are owned by their respective companies.