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.

FOREACH for multiple parameters

myrights99
Graph Buddy

Hello:

I am creating multiple nodes with two properties and later other multiple nodes with four properties. I am trying to do as shown below and getting errors. I want to know whether it is possible to do so and how. Thanking for your help in advance.

def create_multi_node(tx, pLat,pLon):
return tx.run(
"forEach(p in $pLat, p1 in $pLon |\
MERGE (g:Geospat {lat: p,lon:p1}) \
)",pLat=pLat,pLon=pLon
)

session = driver.session(database="tower")

# Execute the `create_mnc_node` "unit of work" within a write transaction
session.execute_write(create_multi_node, pLat=pLat,pLon=pLon)

1 ACCEPTED SOLUTION

Unfortunately, the 'forEach' does not support multiple indexes. You can achieve what you want by using a 'double unwind' as shown below. This will give you every combine of (p, p1). 

unwind $pLat as p
unwind $pLon as p1
MERGE (g:Geospat {lat: p, lon:p1})

 

 

View solution in original post

7 REPLIES 7

Unfortunately, the 'forEach' does not support multiple indexes. You can achieve what you want by using a 'double unwind' as shown below. This will give you every combine of (p, p1). 

unwind $pLat as p
unwind $pLon as p1
MERGE (g:Geospat {lat: p, lon:p1})

 

 

Thanks for your reply. I am using Neo4j Sandbox. When I run the below query, I get the following error on timeout. Not sure if timeout can be changed?

ERROR = ClientError: {code: Neo.ClientError.Transaction.TransactionTimedOut} {message: The transaction has been terminated. Retry your operation in a new transaction, and you should see a successful result. The transaction has not been completed within the specified timeout (dbms.transaction.timeout). You may want to retry with a longer timeout. }

from neo4j import unit_of_work
@unit_of_work(timeout=300) # 5 mins

def create_multi_node(tx, pLat,pLon):
return tx.run(
"unwind $pLat as p \
unwind $pLon as p1 \
MERGE (g:Geospat {lat: p, lon:p1})"
,pLat=pLat,pLon=pLon
)

session = driver.session(database="tower")

# Execute the `create_mnc_node` "unit of work" within a write transaction
session.execute_write(create_multi_node, pLat=pLat,pLon=pLon)

That is not a complex query.  How many elements are in each list?  

Do you have a large database? Do you have a composite index for Geospat on lon and lat properties. 

can you post the query profile? 

I have 2000 records in my CSV file and I am using Jupyter Notebook to connect Neo4j Sandbox using Neo4j Driver.
There is no index on Geospat node as it is failing to create due to timeout.

You mentioned about query profile, how can I get that?

Thank you for your help, I appreciate you.

Maybe you should try using the data importer tool in if it is available in the sandbox. You could just run the query in the browser tool in the sandbox.  You just need your two lists. 

you can profile your query in the browser by adding ‘profile’ at the beginning of the query.  After you run it there will be a new icon on the left to display the plan. 

You can create the index in the browser, it would be beneficial if you had a lot of existing nodes when importing you new nodes 

myrights99
Graph Buddy

Default value on Neo4j Sandbox - "dbms.transaction.timeout" "45s"

I set the new value - CALL dbms.setConfigValue("dbms.transaction.timeout", "300s")

Still getting same error -

he transaction has not completed within the specified timeout (dbms.transaction.timeout). You may want to retry with a longer timeout. }



Can you share your csv?   How many nodes exist in your database?