8.5. Parameters

Cypher supports querying with parameters. This means developers don’t have to resort to string building to create a query. In addition to that, it also makes caching of execution plans much easier for Cypher.

Parameters can be used for literals and expressions in the WHERE clause, for the index value in the START clause, index queries, and finally for node/relationship ids. Parameters can not be used as for property names, relationship types and labels, since these patterns are part of the query structure that is compiled into a query plan.

Accepted names for parameters are letters and numbers, and any combination of these.

For details on using parameters via the Neo4j REST API, see Section 20.1, “Transactional Cypher HTTP endpoint”. For details on parameters when using the Neo4j embedded Java API, see Section 32.17, “Query Parameters”.

Below follows a comprehensive set of examples of parameter usage. The parameters are given as JSON here. Exactly how to submit them depends on the driver in use.

String literal

Parameters 

{
  "name" : "Johan"
}

Query 

MATCH (n)
WHERE n.name = { name }
RETURN n

You can use parameters in this syntax as well:

Parameters 

{
  "name" : "Johan"
}

Query 

MATCH (n { name: { name }})
RETURN n

Regular expression

Parameters 

{
  "regex" : ".*h.*"
}

Query 

MATCH (n)
WHERE n.name =~ { regex }
RETURN n.name

Case-sensitive string pattern matching

Parameters 

{
  "name" : "Michael"
}

Query 

MATCH (n)
WHERE n.name STARTS WITH { name }
RETURN n.name

Create node with properties

Parameters 

{
  "props" : {
    "name" : "Andres",
    "position" : "Developer"
  }
}

Query 

CREATE ({ props })

Create multiple nodes with properties

Parameters 

{
  "props" : [ {
    "awesome" : true,
    "name" : "Andres",
    "position" : "Developer"
  }, {
    "children" : 3,
    "name" : "Michael",
    "position" : "Developer"
  } ]
}

Query 

UNWIND { props } AS properties
CREATE (n:Person)
SET n = properties
RETURN n

Setting all properties on node

Note that this will replace all the current properties.

Parameters 

{
  "props" : {
    "name" : "Andres",
    "position" : "Developer"
  }
}

Query 

MATCH (n)
WHERE n.name='Michaela'
SET n = { props }

SKIP and LIMIT

Parameters 

{
  "s" : 1,
  "l" : 1
}

Query 

MATCH (n)
RETURN n.name
SKIP { s }
LIMIT { l }

Node id

Parameters 

{
  "id" : 0
}

Query 

MATCH (n)
WHERE id(n)= { id }
RETURN n.name

Multiple node ids

Parameters 

{
  "ids" : [ 0, 1, 2 ]
}

Query 

MATCH (n)
WHERE id(n) IN { ids }
RETURN n.name

Index value (legacy indexes)

Parameters 

{
  "value" : "Michaela"
}

Query 

START n=node:people(name = { value })
RETURN n

Index query (legacy indexes)

Parameters 

{
  "query" : "name:Andreas"
}

Query 

START n=node:people({ query })
RETURN n