Running Cypher queries (Deprecated)

Running Cypher queries on an in-memory graph is deprecated and will be removed starting from version 2.7. Due to low adoption and high maintenance costs of this feature there is no replacement planned. If you want to run Cypher queries on an in-memory graph the recommended way is to write back data to Neo4j and run Cypher queries on the database.

This feature is in the alpha tier. For more information on feature tiers, see API Tiers.

This feature is not available in AuraDS.
This feature requires Neo4j Enterprise Edition.

Besides stream procedures, you can also use Cypher queries to inspect nodes and relationships in a graph.

The gds.ephemeral.database.create procedure creates an ephemeral Neo4j database that mirrors your in-memory graph. Once the database is created, you can run Cypher queries on it as you would on any Neo4j database.

Syntax

Creating an ephemeral database

CALL gds.ephemeral.database.create(
    dbName: String
    graphName: String
)
YIELD
    dbName: String,
    graphName: String,
    createMillis: Integer
Table 1. Parameters
Name Type Optional Description

dbName

String

no

The name under which the new database is stored.

graphName

String

no

The name under which the graph is stored in the catalog.

Table 2. Results
Name Type Description

dbName

String

The name under which the new database is stored.

graphName

String

The name under which the graph is stored in the catalog.

createMillis

Integer

The elapsed time to create the database in milliseconds.

Dropping an ephemeral database

CALL gds.ephemeral.database.drop(
    dbName: String
)
YIELD
    dbName: String,
    dropMillis: Integer
Table 3. Parameters
Name Type Optional Description

dbName

String

no

The name of the database to drop.

Table 4. Results
Name Type Description

dbName

String

The name of the dropped database.

dropMillis

Integer

The elapsed time to drop the database in milliseconds.

Example

This example shows the creation of an ephemeral database from a simple social network graph and its usage with Cypher queries.

Setup

Here we create a Neo4j database and project it into memory:

CREATE
  (alice:Person { name: 'Alice', age: 23 }),
  (bob:Person { name: 'Bob', age: 42 }),
  (carl:Person { name: 'Carl', age: 31 }),

  (alice)-[:KNOWS]->(bob),
  (bob)-[:KNOWS]->(alice),
  (alice)-[:KNOWS]->(carl)
Project Person nodes and KNOWS relationships:
CALL gds.graph.project(
  'social_network',
  'Person',
  'KNOWS',
  { nodeProperties: 'age' }
)
YIELD
  graphName, nodeCount, relationshipCount

Next, we create an ephemeral database from the projected graph:

Create a new database gdsdb using our social_network graph:
CALL gds.ephemeral.database.create(
  'gdsdb',
  'social_network'
)

We can use the Neo4j SHOW DATABASES command to verify that the new database has been created successfully:

SHOW DATABASES
YIELD name, requestedStatus, currentStatus, default
RETURN name, requestedStatus, currentStatus, default
ORDER BY name
Table 5. Results
name requestedStatus currentStatus default

"gdsdb"

"online"

"online"

false

"neo4j"

"online"

"online"

true

"system"

"online"

"online"

false

Finally, we switch to the newly created database to start using it:

:use gdsdb

Read query

We can now run a MATCH Cypher query on the in-memory database and check the results:

MATCH (n:Person)-[:KNOWS]->(m:Person) RETURN n.age AS age1, m.age AS age2
ORDER BY age1, age2
Table 6. Results
age1 age2

23

31

23

42

42

23

The returned properties correctly match those from the original graph.

It is important to note that the name property cannot be retrieved from the ephemeral database because it is not present in the projected graph. If you need to retrieve properties from the Neo4j database at the same time, you can use a composite database.

Cleanup

As described above, ephemeral databases are impermanent and are removed when the DBMS is shut down. There are two ways to drop an ephemeral database immediately:

  • Use the gds.ephemeral.database.drop procedure:

    CALL gds.ephemeral.database.drop('gdsdb')
  • Use an administrative command against the system database:

    DROP DATABASE gdsdb

In both cases, you need to switch to a different database before proceeding.

Limitations

Although it is possible to execute arbitrary Cypher queries on the ephemeral database, the database itself is not a plain Neo4j database. As such, not every aspect of Cypher is implemented.

The following operations are not supported:

  • Creating new nodes and adding node labels

  • Creating and updating relationships