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.

Multiple nested apoc.periodic.iterator

Question: How to access Node/ Node properties within multiple nested apoc.periodic.iterator (s) ?

to create sample data:

:params eventParam=> [{eid: "e1"},{eid: "e2"}];

Query:


call apoc.periodic.iterate(
	'
        // create some nodes - *ideally these nodes will be read from some jdbc source*
		UNWIND [1, 2, 3] AS gid
		MERGE (f:FromNode {gid: gid} ) return f 
	',
	' 
       // Run a nested apo.periodic.iterator - procedure to create relationship (FromNode)-[Related]->(Event) - 1 to n relationship
		call apoc.periodic.iterate(
			" unwind $events as ev return ev " , // *ideally events will be derived from (f)'s property
			"  merge (f)-[:RELATED_TO]->(e:Event {eid:ev.eid} ) return e ",
			{params:{events: $events}}
		)  yield batches return batches

// Note there may be more iterators inside
//call apoc.periodic.iterate(
		//	" unwind $alerts as alert return alert " ,
		//	" merge (f)-[:HAS]->(a:Alert{..} ) return a ",
		//	{params:{alerts: $alerts}}
	//	)  yield batches return batches


	',
	{params:{events:$eventParam}, parallel:true}
) 

Actual Output:
3X_2_6_268315c12b8d7ce6ecf2cfe3dcff33ebbbc03ab1.png

Expected Output:
3X_7_2_725cfcd7516efa6e84bf687275def43a653efc23.png

Issue is: FromNode created in first cypherIterator is not accessible in nested iterator while creating relationship

1 REPLY 1

you also need to pass "f" as parameter like you do with events

also best to use id(f) and look up the node/relationship again, as otherwise there might be issues where the tx data of the inner transactions is stored in the main tx.

Also I don't think you need multiple periodic iterates, just use one and move the unwind of the events into the update statement and reduce the batch size.

you should also merge the event in an extra clause otherwise you get one event node per FromNode