# Creating virtual node/rels from output of apoc.path.expand

**URL:** <https://community.neo4j.com/t/creating-virtual-node-rels-from-output-of-apoc-path-expand/21716>\
**Category:** Cypher\
**Tags:** apoc\
**Created:** [July 15, 2020, 10:50pm UTC](https://community.neo4j.com/t/creating-virtual-node-rels-from-output-of-apoc-path-expand/21716 "2020-07-15T22:50:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mike/32/334_2.png) [@mike](https://community.neo4j.com/u/mike)\
**Post date:** [July 15, 2020, 10:50pm UTC](https://community.neo4j.com/t/creating-virtual-node-rels-from-output-of-apoc-path-expand/21716/1 "2020-07-15T22:50:36Z")

</div>

We have a db of UK companies and company officers, using apoc.path.expand:

```auto
MATCH (c:Company) where c.name = "REGULATION TECHNOLOGIES LTD"
call apoc.path.expandConfig(c, {maxLevel:4, relationshipFilter:'HAS_PERSON_RECORD|HAS_COMPANY|HAS_COMPANY_OFFICER', uniqueness:'RELATIONSHIP_GLOBAL'}) YIELD path
RETURN path

```

 ![graphRTL](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/a/a7021f5884014e52184f38fa2abd9a2b743294ee.png)

The final visualisation I want is orange node-blue node-orange node..., i.e. removing the grey node. (With help from the forum previously) made some progress using virtual relationships:

```auto
MATCH (c:Company) where c.name = "REGULATION TECHNOLOGIES LTD"
call apoc.path.expandConfig(c, {maxLevel:4, relationshipFilter:'HAS_PERSON_RECORD|HAS_COMPANY|HAS_COMPANY_OFFICER', uniqueness:'RELATIONSHIP_GLOBAL'}) YIELD path
UNWIND relationships(path) as rel
WITH DISTINCT rel
WITH startNode(rel) as event, collect(DISTINCT endNode(rel)) as toConnect
WITH toConnect[0] as toConnect1, toConnect[1] as toConnect2
CALL apoc.create.vRelationship(toConnect1,'CONNECTED_TO',{}, toConnect2) YIELD rel
RETURN toConnect1, rel, toConnect2

```

![graphRTL2](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/6/64e0ca22ea85a017fa7781b70247f4ab9850ddad.png)

The desired output is to have the blue nodes where the grey ones are. If it's a case of re-working the virtualisation step or some other step after it I have failed to crack it! Any help gratefully received.

Thanks
