Prev |  | Next

## 18.17. Cypher Plugin

| Warning
This functionality is now provided by the core REST API. The plugin will continue to work for some time, but is as of Neo4j 1.6 deprecated. See Section 18.3, “Cypher queries” for documentation on the built-in Cypher support.

The Neo4j Cypher Plugin enables querying with the Chapter 15, Cypher Query Language. The results are returned as a list of string headers (`columns`), and a `data` part, consisting of a list of all rows, every row consisting of a list of REST representations of the field value - `Node`, `Relationship` or any simple value like `String`.

### 18.17.1. Send a Query

A simple query returning all nodes connected to node 1, returning the node and the name property, if it exists, otherwise `null`:

    START x  = node(3)
    MATCH x -[r]-> n
    RETURN type(r), n.name?, n.age?

Figure 18.80. Final Graph

Example request

- `POST` `http://localhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

    {
      "query" : "start x  = node(3) match x -[r]-> n return type(r), n.name?, n.age?",
      "params" : {
      }
    }

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

    {
      "columns" : [ "type(r)", "n.name?", "n.age?" ],
      "data" : [ [ "know", "him", 25 ], [ "know", "you", null ] ]
    }

### 18.17.2. Return paths

Paths can be returned together with other return types by just specifying returns.

    START x  = node(7)
    MATCH path = (x--friend)
    RETURN path, friend.name

Figure 18.81. Final Graph

Example request

- `POST` `http://localhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

    {
      "query" : "start x  = node(7) match path = (x--friend) return path, friend.name",
      "params" : {
      }
    }

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

    {
      "columns" : [ "path", "friend.name" ],
      "data" : [ [ {
        "start" : "http://localhost:7474/db/data/node/7",
        "nodes" : [ "http://localhost:7474/db/data/node/7", "http://localhost:7474/db/data/node/6" ],
        "length" : 1,
        "relationships" : [ "http://localhost:7474/db/data/relationship/3" ],
        "end" : "http://localhost:7474/db/data/node/6"
      }, "you" ] ]
    }

### 18.17.3. Send queries with parameters

Cypher supports queries with parameters which are submitted as a JSON map.

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

Figure 18.82. Final Graph

Example request

- `POST` `http://localhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

    {
      "query" : "start x  = node:node_auto_index(name={startName}) match path = (x-[r]-friend) where friend.name = {name} return TYPE(r)",
      "params" : {
        "startName" : "I",
        "name" : "you"
      }
    }

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

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

### 18.17.4. Server errors

Errors on the server will be reported as a JSON-formatted stacktrace and message.

    START x = node(5)
    RETURN x.dummy

Figure 18.83. Final Graph

Example request

- `POST` `http://localhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

    {
      "query" : "start x = node(5) return x.dummy",
      "params" : {
      }
    }

Example response

- `400:` `Bad Request`
- `Content-Type:` `application/json`

    {
      "message" : "The property 'dummy' does not exist on Node[5]",
      "exception" : "BadInputException",
      "stacktrace" : [ "org.neo4j.server.rest.repr.RepresentationExceptionHandlingIterable.exceptionOnNext(RepresentationExceptionHandlingIterable.java:40)", "org.neo4j.helpers.collection.ExceptionHandlingIterable$1.next(ExceptionHandlingIterable.java:70)", "org.neo4j.helpers.collection.IteratorWrapper.next(IteratorWrapper.java:47)", "org.neo4j.server.rest.repr.ListRepresentation.serialize(ListRepresentation.java:58)", "org.neo4j.server.rest.repr.Serializer.serialize(Serializer.java:75)", "org.neo4j.server.rest.repr.MappingSerializer.putList(MappingSerializer.java:61)", "org.neo4j.server.rest.repr.CypherResultRepresentation.serialize(CypherResultRepresentation.java:50)", "org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:42)", "org.neo4j.server.rest.repr.OutputFormat.format(OutputFormat.java:170)", "org.neo4j.server.rest.repr.OutputFormat.formatRepresentation(OutputFormat.java:120)", "org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:107)", "org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:55)", "org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:122)", "java.lang.reflect.Method.invoke(Method.java:597)" ]
    }

Copyright © 2013 Neo Technology

Prev | Up | Next
| Home |