Neo4j comes with a number of built-in graph algorithms. They are performed from a start node. The traversal is controlled by the URI and the body sent with the request.
The algorithm to choose. If not set, default is shortestPath
.
algorithm
can have one of these values:
shortestPath
allSimplePaths
allPaths
dijkstra
(optional with cost_property
and default_cost
parameters)
1
.
The shortestPath
algorithm can find multiple paths between the same
nodes, like in this example.
Example request
POST
http://localhost:7474/db/data/node/476/paths
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/471", "max_depth" : 3, "relationships" : { "type" : "to", "direction" : "out" }, "algorithm" : "shortestPath" }
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/476", "nodes" : [ "http://localhost:7474/db/data/node/476", "http://localhost:7474/db/data/node/475", "http://localhost:7474/db/data/node/471" ], "length" : 2, "relationships" : [ "http://localhost:7474/db/data/relationship/310", "http://localhost:7474/db/data/relationship/319" ], "end" : "http://localhost:7474/db/data/node/471" }, { "start" : "http://localhost:7474/db/data/node/476", "nodes" : [ "http://localhost:7474/db/data/node/476", "http://localhost:7474/db/data/node/472", "http://localhost:7474/db/data/node/471" ], "length" : 2, "relationships" : [ "http://localhost:7474/db/data/relationship/311", "http://localhost:7474/db/data/relationship/317" ], "end" : "http://localhost:7474/db/data/node/471" } ]
If no path algorithm is specified, a ShortestPath
algorithm with a max
depth of 1 will be chosen. In this example, the max_depth
is set to 3
in order to find the shortest path between 3 linked nodes.
Example request
POST
http://localhost:7474/db/data/node/460/path
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/455", "max_depth" : 3, "relationships" : { "type" : "to", "direction" : "out" }, "algorithm" : "shortestPath" }
Example response
200:
OK
Content-Type:
application/json
{ "start" : "http://localhost:7474/db/data/node/460", "nodes" : [ "http://localhost:7474/db/data/node/460", "http://localhost:7474/db/data/node/456", "http://localhost:7474/db/data/node/455" ], "length" : 2, "relationships" : [ "http://localhost:7474/db/data/relationship/288", "http://localhost:7474/db/data/relationship/294" ], "end" : "http://localhost:7474/db/data/node/455" }
Example request
POST
http://localhost:7474/db/data/node/466/path
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/469", "cost_property" : "cost", "relationships" : { "type" : "to", "direction" : "out" }, "algorithm" : "dijkstra" }
Example response
200:
OK
Content-Type:
application/json
{ "weight" : 2.0, "start" : "http://localhost:7474/db/data/node/466", "nodes" : [ "http://localhost:7474/db/data/node/466", "http://localhost:7474/db/data/node/467", "http://localhost:7474/db/data/node/469" ], "length" : 2, "relationships" : [ "http://localhost:7474/db/data/relationship/297", "http://localhost:7474/db/data/relationship/298" ], "end" : "http://localhost:7474/db/data/node/469" }
Example request
POST
http://localhost:7474/db/data/node/450/path
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/453", "cost_property" : "cost", "relationships" : { "type" : "to", "direction" : "out" }, "algorithm" : "dijkstra" }
Example response
200:
OK
Content-Type:
application/json
{ "weight" : 6.0, "start" : "http://localhost:7474/db/data/node/450", "nodes" : [ "http://localhost:7474/db/data/node/450", "http://localhost:7474/db/data/node/451", "http://localhost:7474/db/data/node/448", "http://localhost:7474/db/data/node/449", "http://localhost:7474/db/data/node/446", "http://localhost:7474/db/data/node/447", "http://localhost:7474/db/data/node/453" ], "length" : 6, "relationships" : [ "http://localhost:7474/db/data/relationship/274", "http://localhost:7474/db/data/relationship/276", "http://localhost:7474/db/data/relationship/278", "http://localhost:7474/db/data/relationship/281", "http://localhost:7474/db/data/relationship/283", "http://localhost:7474/db/data/relationship/284" ], "end" : "http://localhost:7474/db/data/node/453" }
Copyright © 2013 Neo Technology