neo4j

How to query an in-memory "view" of a Neo4j graph?


I want to run Cypher queries on a scoped in-memory graph (akin a "view" in the RDBMS) that would have been extracted from the entire Neo4j graph.

It seems that this apoc is creating the such in-memory graph [1].

CALL apoc.graph.fromCypher(
  'MATCH (p:Person)-[r:DIRECTED]->(m:Movie) RETURN *',
  {},
  'directors',
  {description: "Virtual Graph of all directorships"}
)
YIELD graph AS g
RETURN g;

Questions:

[1] https://neo4j.com/docs/apoc/current/overview/apoc.graph/apoc.graph.fromCypher/


Solution

  • Virtual nodes/relationships are intended for visualization (e.g., the neo4j Browser can display them), and you cannot use them with most Cypher clauses.

    In fact, the doc you mentioned even states:

    This procedure returns virtual nodes and relationships that can only be accessed by other APOC procedures.

    Also, virtual nodes/relationships do not persist between queries.