apoc.refactor.extractNode
Procedure APOC Core
apoc.refactor.extractNode([rel1,rel2,…], [labels],'OUT','IN') extract node from relationships
Signature
apoc.refactor.extractNode(relationships :: ANY?, labels :: LIST? OF STRING?, outType :: STRING?, inType :: STRING?) :: (input :: INTEGER?, output :: NODE?, error :: STRING?)
Input parameters
Name | Type | Default |
---|---|---|
relationships |
ANY? |
null |
labels |
LIST? OF STRING? |
null |
outType |
STRING? |
null |
inType |
STRING? |
null |
Usage Examples
The examples in this section are based on the following sample graph:
CREATE (origin:Airport {code: "LHR"})
CREATE (destination:Airport {code: "AMS"})
CREATE (origin)-[:FLIGHT {number: "BA001"}]->(destination);
The following creates a Flight
node with an IN
relationship from LHR
and an OUT
relationship to AMS
:
MATCH (:Airport)-[rel:FLIGHT]->(:Airport)
WITH collect(rel) AS rels
CALL apoc.refactor.extractNode(rels,['Flight'],'OUT','IN')
YIELD input, output
RETURN input, output;
input | output |
---|---|
0 |
(:Flight {number: "BA001"}) |
We can list all the Flight
nodes by running the following query:
MATCH path = (origin)-[:IN]->(:Flight)-[:OUT]->(destination)
RETURN path;
path |
---|
(:Airport {code: "LHR"})-[:IN]→(:Flight {number: "BA001"})-[:OUT]→(:Airport {code: "AMS"}) |