How do you use parameters with neo4j?

Cypher supports queries with parameters which are submitted as JSON. For example, the following is the REST API usage. For the Java embedded API please refer to the following documentation: http://docs.neo4j.org/chunked/milestone/tutorials-cypher-parameters-java.html

MATCH (x { name: { startName }})-[r]-(friend)
WHERE friend.name = { name }
RETURN TYPE(r)

Example request

POST http://localhost:7474/db/data/cypher
Accept: application/json; charset=UTF-8
Content-Type: application/json 

{
  "query" : "MATCH (x {name: {startName}})-[r]-(friend) WHERE friend.name = {name} RETURN TYPE(r)",
  "params" : {
    "startName" : "I",
    "name" : "you"
  }
}

Example response

200: OK
Content-Type: application/json; charset=UTF-8

{
  "columns" : [ "TYPE(r)" ],
  "data" : [ [ "know" ] ]
}

Parameters are not currently supported in regular Cypher statements in the Neo4j 2.0 browser. However, you can use the :POST syntax to achieve this.

Refer to the documentation for more information on Cypher queries via REST API.

http://docs.neo4j.org/chunked/milestone/rest-api-cypher.html

Update:

The following query allows you to accomplish this in the browser, although it is not an ideal experience:

:POST /db/data/transaction/commit {
    "statements": [
        {
            "statement": "MATCH (u:User {name:{username}}) RETURN u.name as username",
            "parameters": {
                "username": "my name"
            }
        }
    ]
}

Tags:

Neo4J