20.14. Node degree

The node degree is the number of relationships associated with a node. Neo4j stores the degree for each node, making this a useful mechanism to quickly get the number of relationships a node has. You can also optionally filter degree by direction and/or relationship type.

Get the degree of a node

Return the total number of relationships associated with a node.

Figure 20.65. Final Graph

Example request

  • GET http://localhost:7474/db/data/node/19/degree/all
  • Accept: application/json; charset=UTF-8

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
2

Get the degree of a node by direction

Return the number of relationships of a particular direction for a node. Specify all, in or out.

Figure 20.66. Final Graph

Example request

  • GET http://localhost:7474/db/data/node/22/degree/out
  • Accept: application/json; charset=UTF-8

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
2

Get the degree of a node by direction and types

If you are only interested in the degree of a particular relationship type, or a set of relationship types, you specify relationship types after the direction. You can combine multiple relationship types by using the & character.

Figure 20.67. Final Graph

Example request

  • GET http://localhost:7474/db/data/node/16/degree/out/KNOWS&LIKES
  • Accept: application/json; charset=UTF-8

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
3