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"}];


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:

Expected Output:

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

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