Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-15-2022 07:15 AM
Hi,
Running this query:
Match (n:company)<-[:Assigned_to]-(a:patent)-[r:Cites]->(d:patent)-[:Assigned_to]->(n)
where exists {(a)-[:Cites*2..4]->(d)}
set r.inherited =true
Which is known to be heavy. After several hours of running, I got this error message.
I am running from within Neo4J Desktop to a local database.
Any advice on remediation and also how to make the very faster would be welcome.
Andy
06-16-2022 10:47 AM - edited 06-16-2022 10:47 AM
Depending on your data volume you might need to batch it. And use shortestPath in your check.
I think a better version is:
Match (n:company)
call { with n
match (n)<-[:Assigned_to]-(a:patent)-[r:Cites]->(d:patent)-[:Assigned_to]->(n)
where not shortestPath((a)-[:Cites*..4]->(d)) is null
set r.inherited =true
} in transactions of 1000 rows
06-16-2022 12:03 PM
Hi Michael,
Thank you for your reply. For your solution I found that I had to include :auto to avoid an error.
:auto Match (n:company)
call { with n
match (n)<-[:Assigned_to]-(a:patent)-[r:Cites]->(d:patent)-[:Assigned_to]->(n)
where not shortestPath((a)-[:Cites*..4]->(d)) is null
set r.inherited =true
} in transactions of 1000 rows
But also I am not sure the logic is quite in line with what I want to accomplish.
The goal of the query was to identify relationships to grandparents, great grandparent, and great, great grandparents and define them as inherited. So from a shortest path perspective the question becomes if always have a path length of 1 by definition of the initial match statement, but if another path exists then set that initial path to inherited=true.
As an example I have this snippet from my graph, Starting at the node on left, I can reach all of the other nodes directly but I would like to tag the highlighted relationships as inherited. There is a business meaning for this I want to capture. The code you suggested sets them all to inherited which is not the intent. With that in mind, how could I exploit shortestPath? I am almost asking if there is at least one next longer path and if so the original relationship, (a)-[r:Cites]]->(d) r.inherited can be set to true. So the search process does need to find all just at least 1 longer.
Andy
06-16-2022 02:39 PM
A bit more info.
I ran my original query in batch transaction mode with
:auto Match (n:company)
call{ with n
Match (n)<-[:Assigned_to]-(a:patent)-[r:Cites]->(d:patent)-[:Assigned_to]->(n)
where exists {(a)-[:Cites*2..4]->(d)}
set r.inherited =true}
in transactions of 1000 rows
And got a similar error message:
WebSocket connection failure. Due to security constraints in your web browser, the reason for the failure is not available to this Neo4j Driver. Please use your browsers development console to determine the root cause of the failure. Common reasons include the database being unavailable, using the wrong connection URL or temporary network problems. If you have enabled encryption, ensure your browser is configured to trust the certificate Neo4j is configured to use. WebSocket `readyState` is: 3
This occurred after ~1 hr or processing. Also upon inspection no relationships got set with the inherited property. I know that there exists such cases and my original query without the :auto and in transactions was successful in setting the property.
Andy
All the sessions of the conference are now available online