Nearest neighbor to a node from a set of nodes of specific type

I don't have access to the sample data but ...

With your top two matches, you end up trying to compute the shortest path between all possible crossroad pairs's. With 500,000 crossroads you are going to have probably billions of combos ... not good!

Instead collect a list of all possible poi types and loop over this list ...

match (p:POI)
with collect(distinct p.type) as poitypes
unwind poitypes as poitype
...

then need to fill in the code then to match each crossroad against the nearest poi of each type. Once you find the nearest poi, maybe add a new link but remember there could be multiple, equally closest coffee-shop from a corner e.g.

1 Like