Querying Neo4J

The function neo4j_query() can be used to send a query to a local or remote Neo4J server. This function uses cypher-shell to send the query to Neo4J, and so the cypher-shell executable needs to be installed and available locally. See the README file for further information on configuration of the cypher-shell executable.

neo4j_query() takes the following arguments:

Example, assuming a local Neo4J instance running the movies graph:


neo4j_local <- list(address = "bolt://localhost", uid = "neo4j", pwd = "password")
CQL <- 'MATCH (p1:Person {name: "Kevin Bacon"})-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(p2:Person)
        RETURN p2.name AS Name, m.title AS Title'
cypher_path <- path.expand("~/neo4j-community-4.0.4/bin/cypher-shell")
neo4j_query(con = neo4j_local, qry = CQL, shell_path = cypher_path)

This query should return this dataframe:

#>         Name          Title
#> 1 Ron Howard    Frost/Nixon
#> 2 Rob Reiner A Few Good Men
#> 3 Ron Howard      Apollo 13

neo4j_query() accepts multiple query statements separated by ;. The function returns one of the following:

Note for Windows users

Paths to executable files that are provided as arguments to functions may need to be provided with appropriate extensions (eg cypher-shell.bat).