Search code examples
neo4jcypher

Projecting Neo4j Graphs Using Cypher and GDS


I am using the following query to create in memory graph:

CALL gds.graph.project.cypher(
'testgraph2', 
'MATCH (n:Function) RETURN id(n) AS id',
'MATCH (n:Function)-[r:CALLS]->(m:Function) RETURN id(n) AS source, id(m) AS target')

However, I do not want to take all the nodes, instead I want to include only the nodes that have any incoming or outcoming edges. How can I achieve this?


Solution

  • Instead of this:

    MATCH (n:Function) RETURN id(n) AS id
    

    use this:

    MATCH (n:Function) WHERE EXISTS((n)--()) RETURN id(n) AS id