Procedures and Functions

User-defined procedures and functions

User Defined Procedures and Functions are available within Cypher® and encapsulate dedicated functionality.

Just by annotating methods of a Java class and deploying the resulting jar file into your Neo4j installation, you can make new functionality easily available within the query language.

To implement your procedures or functions you would use the Neo4j Embedded Java API. Besides an object-oriented API to the graph database, working with Node, Relationship, and Path objects, it also offers highly customizable, high-speed traversal- and graph-algorithm implementations.

We don’t provide code examples for the Java API on this page, because they are covered in detail in the Java developers manual.

Neo4j uses that functionality itself for built-in procedures for meta-data, cluster-, query- and user-management and more.

Several libraries already provide capabilities using procedures and functions. Below is an example from the APOC library.

MATCH (start:City {name: 'Berlin'}),(end:City {name: 'Malmö'})
CALL apoc.algo.dikjstra(start, end, "ROUTE","distance") yield path, weight
RETURN path
ORDER BY weight ASC LIMIT 10

To get you started we provided a template project and documentation in the Java developer manual.