Prev |  | Next

## 33.13. Query Parameters

For more information on parameters see Section 7.5, “Parameters”.

Below follows example of how to use parameters when executing Cypher queries from Java.

Node id.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "id", 0 );
    String query = "START n=node({id}) RETURN n.name";
    ExecutionResult result = engine.execute( query, params );

Node object.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "node", andreasNode );
    String query = "START n=node({node}) RETURN n.name";
    ExecutionResult result = engine.execute( query, params );

Multiple node ids.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "id", Arrays.asList( 0, 1, 2 ) );
    String query = "START n=node({id}) RETURN n.name";
    ExecutionResult result = engine.execute( query, params );

String literal.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "name", "Johan" );
    String query = "MATCH (n) WHERE n.name = {name} RETURN n";
    ExecutionResult result = engine.execute( query, params );

Index value.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "value", "Michaela" );
    String query = "START n=node:people(name = {value}) RETURN n";
    ExecutionResult result = engine.execute( query, params );

Index query.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "query", "name:Andreas" );
    String query = "START n=node:people({query}) RETURN n";
    ExecutionResult result = engine.execute( query, params );

Numeric parameters for `SKIP` and `LIMIT`.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "s", 1 );
    params.put( "l", 1 );
    String query = "MATCH (n) RETURN n.name SKIP {s} LIMIT {l}";
    ExecutionResult result = engine.execute( query, params );

Regular expression.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "regex", ".*h.*" );
    String query = "MATCH (n) WHERE n.name =~ {regex} RETURN n.name";
    ExecutionResult result = engine.execute( query, params );

Create node with properties.

    Map<String, Object> props = new HashMap<String, Object>();
    props.put( "name", "Andres" );
    props.put( "position", "Developer" );

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "props", props );
    String query = "CREATE ({props})";
    engine.execute( query, params );

Create multiple nodes with properties.

    Map<String, Object> n1 = new HashMap<String, Object>();
    n1.put( "name", "Andres" );
    n1.put( "position", "Developer" );
    n1.put( "awesome", true );

    Map<String, Object> n2 = new HashMap<String, Object>();
    n2.put( "name", "Michael" );
    n2.put( "position", "Developer" );
    n2.put( "children", 3 );

    Map<String, Object> params = new HashMap<String, Object>();
    List<Map<String, Object>> maps = Arrays.asList( n1, n2 );
    params.put( "props", maps );
    String query = "CREATE (n:Person {props}) RETURN n";
    engine.execute( query, params );

Setting all properties on node.

    Map<String, Object> n1 = new HashMap<>();
    n1.put( "name", "Andres" );
    n1.put( "position", "Developer" );

    Map<String, Object> params = new HashMap<>();
    params.put( "props", n1 );

    String query = "MATCH (n) WHERE n.name='Michaela' SET n = {props}";
    engine.execute( query, params );

Copyright © 2014 Neo Technology

Prev | Up | Next
| Home |