Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-29-2021 08:40 AM
In my graph model, nodes have relationships with each other and can have loops. I want to find the nodes in paths of length 2 with distinct nodes in the paths and for a list of beginning nodes:
WITH ['begin1', 'begin2', 'begin3'] as names
MATCH pathlengthtwo= (startNode:Node)-[:link*2]->(finishNode:Node)
where (startNode.name in names) AND (isEmpty ((finishNode)-[:link]->(finishNode)))//to make nodes of the path distinct
RETURN startNode,finishNode, pathlengthtwo limit 10
But Neo4j just gives some nodes (not relationships) for 'begin1' node and I think this is because the paths of the starting node'begin1' go beyond limit 10 and Neo4j even doesn't consider the rest of nodes in the list. How should I change this query to show paths for all the starting nodes in the list and their relationships (not just the nodes)
08-29-2021 10:46 AM
RETURN pathlengthtwo displays nodes and relationships. nodes(pathlengthtwo) gives nodes in the path, relationships(pathlengthtwo) gives the relationships
08-29-2021 11:54 AM
"relationships(pathlengthtwo) "does not help the query to consider the paths starting from 'begin2', 'begin3', Still they are not considered by the query.
08-30-2021 05:11 PM
Hi,
@ameyasoft is right. If you have issues about not seeing some paths, remove the limit. Are you sure you have paths within the other begin's. Debug it removing begin1 of the list.
Btw, the second condition doesn't give you the distinct nodes rule.
You need something like:
WHERE NONE (n IN nodes(pathlengthtwo)
WHERE size(filter(x IN nodes(pathlengthtwo )
WHERE n = x))> 1)
Bennu
All the sessions of the conference are now available online