'How to fetch subgraph in neo4j such that the relationship's weight satisfy a comparison condition?
Imagine I have a huge graph. All the relationships have this numerical property called 'weight'. I want to fetch a subgraph comprised of a specified central node (by id) and its neighbors connected to it by relationships with weight greater than, say, 0.9.
I was trying to use APOC, but apparently, there is not an out-of-the-box option to establish a condition on the relationships.
MATCH (n:Assay {assay_id: "9995-6"})
CALL apoc.path.subgraphAll(n, {
relationshipFilter: "LINK",
minLevel: 1,
maxLevel: 1
})
YIELD nodes
RETURN node,n, LIMIT 25
For example, I would want to add a line like so:
MATCH (n:Assay {assay_id: "9995-6"})
CALL apoc.path.subgraphAll(n, {
relationshipFilter: "LINK",
minLevel: 1,
maxLevel: 1,
r.weight > 0.9 #this line
})
YIELD nodes
RETURN node,n, LIMIT 25
But of course, that does not work. I hope there is a straightforward solution to this. Thank you.
Solution 1:[1]
You can filter the relationships after you get the subgraph. Line 8 below with filter those relationships with wt > .9. Just ignore the visualization of the subgraph in the browser since this query is a some sort of a hack.
MATCH (n:Assay {assay_id: "9995-6"})
CALL apoc.path.subgraphAll(n, {
relationshipFilter: "LINK",
minLevel: 1,
maxLevel: 1
})
YIELD nodes, relationships
WITH nodes, [r in relationships where r.wt > .9|r] as relationships
RETURN nodes, relationships LIMIT 25
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jose_bacoy |
