cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Creating relationships with apoc.load.xml on existing nodes

Michel
Node Clone

Hi,

I have succesfully load elemenst with apoc.load.xml  and now I want to create with that data relationships between nodes, they are already in the database:

 

 

// it works fine, it returns a list of begin ,end pairs (5 pairs) :

WITH
	 [item in children3 WHERE item._type = "begin"][0]  AS begin,	 
	 [item in children4 WHERE item._type = "end"][0]    AS end

// I want to bind cities with relatioship "CONNECTED", but the following  statements makes only the very first relationship. What ist here wrong ?

Match (a:city), (b:city)	 
WHERE a.name = begin._text AND b.name = end._text	 
CREATE (a)-[:CONNECTED]->(b)

 

 

Could you please give me some instructions to solve the issue ?

Thanks,

Michel

 

 

 

 

1 REPLY 1

What does this return: 

[item in children3 WHERE item._type = "begin"]

Is it a list of cities that represent the beginning of the relationship?  If true, then your could would just pull the first one when you use index '0', as below:

[item in children3 WHERE item._type = "begin"][0]  AS begin

Assuming my assumption is correct, then you can do something like the following:

with
	 [item in children3 WHERE item._type = "begin"] AS beginCities,	 
	 [item in children4 WHERE item._type = "end"]   AS endCities
unwind range(0,size(beginCities)-1) as index
Match (a:city), (b:city)	 
WHERE a.name = beginCities[index]._text AND b.name = endCities[index]._text	 
CREATE (a)-[:CONNECTED]->(b)