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.12, “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
.
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?
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
{ "data" : [ [ "know", "him", 25 ], [ "know", "you", null ] ], "columns" : [ "TYPE(r)", "n.name", "n.age" ] }
Paths can be returned together with other return types by just specifying returns.
START x = node(%I%) MATCH path = (x--friend) RETURN path, friend.name
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
{ "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" ] ], "columns" : [ "path", "friend.name" ] }
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)
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
{ "data" : [ [ "know" ] ], "columns" : [ "TYPE(r)" ] }
Errors on the server will be reported as a JSON-formatted stacktrace and message.
START x = node(%I%) RETURN x.dummy
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" : "org.neo4j.server.rest.repr.BadInputException: The property 'dummy' does not exist on Node[5]", "stacktrace" : [ "org.neo4j.server.plugin.cypher.CypherPlugin.executeScript(CypherPlugin.java:81)", "sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", "sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)", "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)", "java.lang.reflect.Method.invoke(Method.java:597)", "org.neo4j.server.plugins.PluginMethod.invoke(PluginMethod.java:57)", "org.neo4j.server.plugins.PluginManager.invoke(PluginManager.java:168)", "org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:300)", "org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:122)", "sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", "sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)", "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)", "java.lang.reflect.Method.invoke(Method.java:597)", "com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:187)", "com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:71)", "com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:280)", "com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)", "com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)", "com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)", "com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)", "com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1341)", "com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1273)", "com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1223)", "com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1213)", "com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)", "com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)", "com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)", "javax.servlet.http.HttpServlet.service(HttpServlet.java:820)", "org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)", "org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)", "org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)", "org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)", "org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)", "org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)", "org.mortbay.jetty.Server.handle(Server.java:326)", "org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)", "org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)", "org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)", "org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)", "org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)", "org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)", "org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)" ] }
Copyright © 2012 Neo Technology