7.5. Parameters

7.5.1. String literal
7.5.2. Regular expression
7.5.3. Create node with properties
7.5.4. Create multiple nodes with properties
7.5.5. Setting all properties on node
7.5.6. SKIP and LIMIT
7.5.7. Node id
7.5.8. Multiple node ids
7.5.9. Index value (legacy indexes)
7.5.10. Index query (legacy indexes)

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 parameters when using the Neo4j embedded Java API, see Section 32.13, “Query Parameters”. For details on using parameters via the Neo4j REST API, see Section 19.5, “Cypher queries via REST”.

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.

7.5.1. String literal

Parameters. 

{
  "name" : "Johan"
}

Query. 

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

7.5.2. Regular expression

Parameters. 

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

Query. 

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

7.5.3. Create node with properties

Parameters. 

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

Query. 

CREATE ({ props })

7.5.4. Create multiple nodes with properties

Parameters. 

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

Query. 

CREATE (n:Person { props })
RETURN n

7.5.5. Setting all properties on node

Note that this will replace all the current properties.

Parameters. 

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

Query. 

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

7.5.6. SKIP and LIMIT

Parameters. 

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

Query. 

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

7.5.7. Node id

Parameters. 

{
  "id" : 0
}

Query. 

START n=node({ id })
RETURN n.name

7.5.8. Multiple node ids

Parameters. 

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

Query. 

START n=node({ id })
RETURN n.name

7.5.9. Index value (legacy indexes)

Parameters. 

{
  "value" : "Michaela"
}

Query. 

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

7.5.10. Index query (legacy indexes)

Parameters. 

{
  "query" : "name:Andreas"
}

Query. 

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