Adding a label to a node
Example request
-
POST
http://localhost:7474/db/data/node/70/labels
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
"Person"
Example response
-
204:
No Content
Adding multiple labels to a node
Example request
-
POST
http://localhost:7474/db/data/node/81/labels
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
[ "Person", "Actor" ]
Example response
-
204:
No Content
Adding a label with an invalid name
Labels with empty names are not allowed, however, all other valid strings are accepted as label names. Adding an invalid label to a node will lead to a HTTP 400 response.
Example request
-
POST
http://localhost:7474/db/data/node/88/labels
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
""
Example response
-
400:
Bad Request
-
Content-Type:
application/json; charset=UTF-8
{ "message": "Unable to add label, see nested exception.", "exception": "BadInputException", "fullname": "org.neo4j.server.rest.repr.BadInputException", "stackTrace": [ "org.neo4j.server.rest.web.DatabaseActions.addLabelToNode(DatabaseActions.java:310)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addNodeLabel(RestfulGraphDatabase.java:446)", "java.lang.reflect.Method.invoke(Method.java:497)", "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:145)", "org.neo4j.server.rest.dbms.AuthorizationDisabledFilter.doFilter(AuthorizationDisabledFilter.java:48)", "org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)", "java.lang.Thread.run(Thread.java:745)" ], "cause": { "exception": "ConstraintViolationException", "cause": { "exception": "IllegalTokenNameException", "fullname": "org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException", "stackTrace": [ "org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations.checkValidTokenName(DataIntegrityValidatingStatementOperations.java:255)", "org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations.labelGetOrCreateForName(DataIntegrityValidatingStatementOperations.java:88)", "org.neo4j.kernel.impl.api.OperationsFacade.labelGetOrCreateForName(OperationsFacade.java:874)", "org.neo4j.kernel.impl.core.NodeProxy.addLabel(NodeProxy.java:582)", "org.neo4j.server.rest.web.DatabaseActions.addLabelToNode(DatabaseActions.java:305)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addNodeLabel(RestfulGraphDatabase.java:446)", "java.lang.reflect.Method.invoke(Method.java:497)", "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:145)", "org.neo4j.server.rest.dbms.AuthorizationDisabledFilter.doFilter(AuthorizationDisabledFilter.java:48)", "org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)", "java.lang.Thread.run(Thread.java:745)" ], "message": "\u0027\u0027 is not a valid token name. Only non-null, non-empty strings are allowed.", "errors": [ { "code": "Neo.ClientError.Schema.TokenNameError", "message": "\u0027\u0027 is not a valid token name. Only non-null, non-empty strings are allowed." } ] }, "fullname": "org.neo4j.graphdb.ConstraintViolationException", "stackTrace": [ "org.neo4j.kernel.impl.core.NodeProxy.addLabel(NodeProxy.java:592)", "org.neo4j.server.rest.web.DatabaseActions.addLabelToNode(DatabaseActions.java:305)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addNodeLabel(RestfulGraphDatabase.java:446)", "java.lang.reflect.Method.invoke(Method.java:497)", "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:145)", "org.neo4j.server.rest.dbms.AuthorizationDisabledFilter.doFilter(AuthorizationDisabledFilter.java:48)", "org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)", "java.lang.Thread.run(Thread.java:745)" ], "message": "Invalid label name \u0027\u0027.", "errors": [ { "code": "Neo.ClientError.Schema.ConstraintValidationFailed", "message": "Invalid label name \u0027\u0027." } ] }, "errors": [ { "code": "Neo.ClientError.Request.InvalidFormat", "message": "Unable to add label, see nested exception." } ] }
Replacing labels on a node
This removes any labels currently on a node, and replaces them with the labels passed in as the request body.
Example request
-
PUT
http://localhost:7474/db/data/node/71/labels
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
[ "Actor", "Director" ]
Example response
-
204:
No Content
Removing a label from a node
Example request
-
DELETE
http://localhost:7474/db/data/node/72/labels/Person
-
Accept:
application/json; charset=UTF-8
Example response
-
204:
No Content
Removing a non-existent label from a node
Example request
-
DELETE
http://localhost:7474/db/data/node/73/labels/Person
-
Accept:
application/json; charset=UTF-8
Example response
-
204:
No Content
Listing labels for a node
Example request
-
GET
http://localhost:7474/db/data/node/77/labels
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
[ "Actor", "Director" ]
Get all nodes with a label
Example request
-
GET
http://localhost:7474/db/data/label/Actor/nodes
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
[ { "metadata" : { "id" : 82, "labels" : [ "Actor" ] }, "data" : { "name" : "Donald Sutherland" }, "paged_traverse" : "http://localhost:7474/db/data/node/82/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/82/relationships/out", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/82/relationships/out/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/82/relationships", "labels" : "http://localhost:7474/db/data/node/82/labels", "traverse" : "http://localhost:7474/db/data/node/82/traverse/{returnType}", "extensions" : { }, "all_relationships" : "http://localhost:7474/db/data/node/82/relationships/all", "all_typed_relationships" : "http://localhost:7474/db/data/node/82/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/82/properties/{key}", "self" : "http://localhost:7474/db/data/node/82", "incoming_relationships" : "http://localhost:7474/db/data/node/82/relationships/in", "properties" : "http://localhost:7474/db/data/node/82/properties", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/82/relationships/in/{-list|&|types}" }, { "metadata" : { "id" : 84, "labels" : [ "Actor", "Director" ] }, "data" : { "name" : "Clint Eastwood" }, "paged_traverse" : "http://localhost:7474/db/data/node/84/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/84/relationships/out", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/84/relationships/out/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/84/relationships", "labels" : "http://localhost:7474/db/data/node/84/labels", "traverse" : "http://localhost:7474/db/data/node/84/traverse/{returnType}", "extensions" : { }, "all_relationships" : "http://localhost:7474/db/data/node/84/relationships/all", "all_typed_relationships" : "http://localhost:7474/db/data/node/84/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/84/properties/{key}", "self" : "http://localhost:7474/db/data/node/84", "incoming_relationships" : "http://localhost:7474/db/data/node/84/relationships/in", "properties" : "http://localhost:7474/db/data/node/84/properties", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/84/relationships/in/{-list|&|types}" } ]
Get nodes by label and property
You can retrieve all nodes with a given label and property by passing one property as a query parameter. Notice that the property value is JSON-encoded and then URL-encoded.
If there is an index available on the label/property combination you send, that index will be used. If no index is available, all nodes with the given label will be filtered through to find matching nodes.
Currently, it is not possible to search using multiple properties.
Example request
-
GET
http://localhost:7474/db/data/label/Person/nodes?name=%22Clint+Eastwood%22
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
[ { "metadata" : { "id" : 87, "labels" : [ "Person" ] }, "data" : { "name" : "Clint Eastwood" }, "paged_traverse" : "http://localhost:7474/db/data/node/87/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/87/relationships/out", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/87/relationships/out/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/87/relationships", "labels" : "http://localhost:7474/db/data/node/87/labels", "traverse" : "http://localhost:7474/db/data/node/87/traverse/{returnType}", "extensions" : { }, "all_relationships" : "http://localhost:7474/db/data/node/87/relationships/all", "all_typed_relationships" : "http://localhost:7474/db/data/node/87/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/87/properties/{key}", "self" : "http://localhost:7474/db/data/node/87", "incoming_relationships" : "http://localhost:7474/db/data/node/87/relationships/in", "properties" : "http://localhost:7474/db/data/node/87/properties", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/87/relationships/in/{-list|&|types}" } ]
List all labels
By default, the server will return labels in use only. If you also want to return labels not in use, append the "in_use=0" query parameter.
Example request
-
GET
http://localhost:7474/db/data/labels
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
[ "Actor", "Director", "Person" ]