The Neo4j Cypher Plugin enables querying with the Chapter 16, 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)" ] }
The plugin can return a JSONTable representation of the results. For details, see Google Data Table Format
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(9) 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/9", "nodes" : [ "http://localhost:7474/db/data/node/9", "http://localhost:7474/db/data/node/8" ], "length" : 1, "relationships" : [ "http://localhost:7474/db/data/relationship/4" ], "end" : "http://localhost:7474/db/data/node/8" }, "you" ] ], "columns" : [ "path", "friend.name" ] }
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" : "dummy property not found for NodeImpl#5.", "exception" : "org.neo4j.graphdb.NotFoundException: dummy property not found for NodeImpl#5.", "stacktrace" : [ "org.neo4j.kernel.impl.core.Primitive.newPropertyNotFoundException(Primitive.java:173)", "org.neo4j.kernel.impl.core.Primitive.getProperty(Primitive.java:168)", "org.neo4j.kernel.impl.core.NodeProxy.getProperty(NodeProxy.java:146)", "org.neo4j.cypher.commands.PropertyValue.apply(Value.scala:69)", "org.neo4j.cypher.commands.PropertyValue.apply(Value.scala:62)", "org.neo4j.cypher.commands.ValueReturnItem.apply(ReturnItem.scala:38)", "org.neo4j.cypher.commands.ValueReturnItem.apply(ReturnItem.scala:37)", "org.neo4j.cypher.pipes.TransformPipe$$anonfun$foreach$1$$anonfun$3.apply(TransformPipe.scala:39)", "org.neo4j.cypher.pipes.TransformPipe$$anonfun$foreach$1$$anonfun$3.apply(TransformPipe.scala:39)", "scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)", "scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)", "scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)", "scala.collection.immutable.List.foreach(List.scala:45)", "scala.collection.TraversableLike$class.map(TraversableLike.scala:194)", "scala.collection.immutable.List.map(List.scala:45)", "org.neo4j.cypher.pipes.TransformPipe$$anonfun$foreach$1.apply(TransformPipe.scala:39)", "org.neo4j.cypher.pipes.TransformPipe$$anonfun$foreach$1.apply(TransformPipe.scala:38)", "org.neo4j.cypher.pipes.StartPipe$$anonfun$foreach$1$$anonfun$apply$1.apply(StartPipe.scala:36)", "org.neo4j.cypher.pipes.StartPipe$$anonfun$foreach$1$$anonfun$apply$1.apply(StartPipe.scala:35)", "scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)", "scala.collection.immutable.List.foreach(List.scala:45)", "org.neo4j.cypher.pipes.StartPipe$$anonfun$foreach$1.apply(StartPipe.scala:35)", "org.neo4j.cypher.pipes.StartPipe$$anonfun$foreach$1.apply(StartPipe.scala:34)", "org.neo4j.cypher.pipes.ParameterPipe.foreach(ParameterPipe.scala:27)", "org.neo4j.cypher.pipes.StartPipe.foreach(StartPipe.scala:34)", "org.neo4j.cypher.pipes.TransformPipe.foreach(TransformPipe.scala:38)", "org.neo4j.cypher.pipes.ColumnFilterPipe.foreach(ColumnFilterPipe.scala:35)", "scala.collection.TraversableLike$class.map(TraversableLike.scala:194)", "org.neo4j.cypher.pipes.Pipe.map(Pipe.scala:31)", "org.neo4j.cypher.ExecutionResult$class.javaIterator(ExecutionResult.scala:48)", "org.neo4j.cypher.pipes.ColumnFilterPipe.javaIterator(ColumnFilterPipe.scala:25)", "org.neo4j.cypher.javacompat.ExecutionResult.iterator(ExecutionResult.java:51)", "org.neo4j.server.rest.repr.CypherResultRepresentation.data(CypherResultRepresentation.java:54)", "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.rest.repr.ObjectRepresentation$1.get(ObjectRepresentation.java:92)", "org.neo4j.server.rest.repr.ObjectRepresentation$PropertyGetter.putTo(ObjectRepresentation.java:131)", "org.neo4j.server.rest.repr.ObjectRepresentation.serialize(ObjectRepresentation.java:143)", "org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:42)", "org.neo4j.server.rest.repr.OutputFormat.format(OutputFormat.java:123)", "org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:100)", "org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:48)", "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