Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-28-2021 05:43 AM
Hi All,
Suppose I have this path in my graph, and want to return this path.
I have written the below query but if I write this I am not getting the Capacity Node. I want to expand the node connected to the Production Node.
match p=(:WIPCapacity)-[:throughput]->(d:WIPProduction)-[r4:transport]->(e:WIPStorage)-[r5:transport]->(f:WIPStorage)-[r7:transport]->(h:Production)-[r8:transport]->(i:Storage)-[r9:transport]->(j:Storage)-[r10:transport]->(k:Storage)
return p;
Please let me know if you can suggest how to write the cypher query to get the full path.
Thanks,
Pragya
Solved! Go to Solution.
11-07-2021 11:35 PM
Here is my result:
I created this:
merge (a:WIPProduction {name: "WIPP1"})
merge (b:WIPCapacity {name: "CAP1"})
merge (c1:WIPStorage {name: "STOR1"})
merge (c2:WIPStorage {name: "STOR2"})
merge (a1:Production {name: "P1"})
merge (b)-[:throughput]->(a)
merge (a)-[:transport]->(c1)
merge (c1)-[:transport]->(c2)
merge (c2)-[:transport]->(a1)
merge (b1:Capacity {name: "CAP2"})
merge (b1)-[:throughput]->(a1)
merge (c3:Storage {name: "STOR3"})
merge (c4:Storage {name: "STOR4"})
merge (c5:Storage {name: "STOR5"})
merge (a1)-[:transport]->(c3)
merge (c3)-[:transport]->(c4)
merge (c4)-[:transport]->(c5)
Result:
Ran this query:
MATCH (p:Capacity {name: "CAP2"})
CALL apoc.path.subgraphNodes(p, {
relationshipFilter: '<transport|throughput',
minLevel: 0,
maxLevel: 8
})
YIELD node
RETURN node;
Result:
10-28-2021 10:13 PM
Try this:
MATCH (a:WIPCapacity)
//Add this to select a specific node.....
//WHERE a.name = "CAP1"
//End....
CALL apoc.path.spanningTree(a, {}) YIELD path
return path
10-29-2021 08:31 AM
Hi Ameya,
Thanks
This works and it gives me the full path, but if I know the name of Capacity Node
, and want to return the Node WIP Capacity
which is connected to that so for this I tried something similar like you did using apoc.
I tried this, but its not returning the WIPCapacity, its giving Capacity Node only in output:
MATCH (p:Capacity {name: "CAP1"})
CALL apoc.path.subgraphNodes(p, {
relationshipFilter: "transport|throughput", labelFilter: "WIPCapacity"
minLevel: 0,
maxLevel: 8
})
YIELD node
RETURN node;
10-31-2021 11:31 PM
Try this:
MATCH (p:Capacity {name: "CAP1"})
CALL apoc.path.subgraphNodes(p, {
relationshipFilter: '<transport|throughput',
minLevel: 0,
maxLevel: 8
})
YIELD node
RETURN node;
Change the relationshipFilter to this to go towards 'Storage' nodes. '<' indicates 'incoming' diretction
relationshipFilter: 'transport|throughput'
11-07-2021 09:25 PM
I tried this, still its returning the Capacity Node in the output and not giving me the WIPCapacity Node which is expected.
11-07-2021 11:35 PM
Here is my result:
I created this:
merge (a:WIPProduction {name: "WIPP1"})
merge (b:WIPCapacity {name: "CAP1"})
merge (c1:WIPStorage {name: "STOR1"})
merge (c2:WIPStorage {name: "STOR2"})
merge (a1:Production {name: "P1"})
merge (b)-[:throughput]->(a)
merge (a)-[:transport]->(c1)
merge (c1)-[:transport]->(c2)
merge (c2)-[:transport]->(a1)
merge (b1:Capacity {name: "CAP2"})
merge (b1)-[:throughput]->(a1)
merge (c3:Storage {name: "STOR3"})
merge (c4:Storage {name: "STOR4"})
merge (c5:Storage {name: "STOR5"})
merge (a1)-[:transport]->(c3)
merge (c3)-[:transport]->(c4)
merge (c4)-[:transport]->(c5)
Result:
Ran this query:
MATCH (p:Capacity {name: "CAP2"})
CALL apoc.path.subgraphNodes(p, {
relationshipFilter: '<transport|throughput',
minLevel: 0,
maxLevel: 8
})
YIELD node
RETURN node;
Result:
11-07-2021 11:46 PM
Thank You for the explanation, I am also getting this correct till here but instead of this full path that we get in result can I just get the CAP1 node and its properties ?
Is there a way to put where condition, as my main goal is to check the properties of CAP1 and CAP2 which are on the same path, and compare the value of a particular property, then return the node where the value of a particular property( Required_Capacity) is greater.
I hope I am able to explain my use case properly.
Thanks,
Pragya
11-08-2021 12:02 AM
MATCH (p {name: "CAP2"})
CALL apoc.path.subgraphNodes(p, {
relationshipFilter: "<transport|throughput",
minLevel: 0,
maxLevel: 8
})
YIELD node
where node.Available_Capacity<node.Required_Capacity
return node.name, node.Required_Capacity-node.Available_Capacity as d order by d desc;
I tried this putting where condition and returning the desired propeties and this seems to give me the correct output.
I hope this implementation is correct and we can add further steps if required in this query.
All the sessions of the conference are now available online