match (m:Machine{name:'DC1-RCK-1-2-M-3'}), (m2:Machine{name:'DC1-RCK-1-4-M-45'})
match path = shortest 1 (m)-[:!TYPE&!HOLDS]-+(m2)
where not any(node in nodes(path) where 'DataCenter' in labels(node) or 'Version' in labels(node))
return path
Started streaming 1 records after 6 ms and completed after 6 ms.
match (m) where elementId(m) in $nodes
match (m2) where elementId(m2) in $nodes
match path = shortest 1 (m)-[:!TYPE&!HOLDS]-+(m2)
where not any(node in nodes(path) where 'DataCenter' in labels(node) or 'Version' in labels(node))
return path
This took about 33 seconds!
match (m:Machine{name:'DC1-RCK-1-2-M-3'}), (m2:Machine{name:'DC1-RCK-1-4-M-45'})
match path = shortest 1 (m)-[:!TYPE&!HOLDS]-+(m2)
where not any(node in nodes(path) where 'DataCenter' in labels(node) or 'Version' in labels(node))
return path
Query 2 (modified):
:params { nodes: [ 'DC1-RCK-1-2-M-3','DC1-RCK-1-4-M-45' ] }
match (m) where m.name in $nodes
match (m2) where m2.name in $nodes
match path = shortest 1 (m)-[:!TYPE&!HOLDS]-+(m2)
where not any(node in nodes(path) where 'DataCenter' in labels(node) or 'Version' in labels(node))
return path
This bit of your query: (m)-[:!TYPE&!HOLDS]-+(m2) combines the traversal m = M-3 -> M-45 and M45 -> 3 because your 2nd query is on the list in $nodes, while the first is on the node M3 only
Re:times - both queries were pants for me ... Q1 took 25 seconds and Q2 double at 50 secs - but i just ran it cold.
Thank you for the kind explanations.
I modified the query as below, and it worked quickly and correctly:
match (m) where elementId(m) in $nodes
with collect(m) as nodes
CALL apoc.path.expandConfig(nodes[0], {
labelFilter: "-DataCenter|-Version|-Type",
endNodes: [nodes[1]],
minLevel: 2,
uniqueness: "RELATIONSHIP_PATH"
}) YIELD path
RETURN path LIMIT 1
If the query takes long time for you to run, adding an index on the name property will make it fast.
:params { nodes: [ 'DC1-RCK-1-2-M-3','DC1-RCK-1-4-M-45' ] }
WITH $nodes[0] AS node1, $nodes[1] AS node2
WITH node1, node2
match (m) where m.name = node1
match (m2) where m2.name = node2
match path = shortest 1 (m)-[:!TYPE&!HOLDS]-+(m2)
where not any(node in nodes(path) where 'DataCenter' in labels(node) or 'Version' in labels(node))
return path
When I was developing the query, I initially tried like
match (m) where elementId(m) = $nodes[0]
But it didn't work(I am not sure why).
However "match (m) where elementId(m) in $nodes" works, so I used that before.
I think the query below should work, but it doesn't:
match (m) where elementId(m) in $nodes
with collect(m) as nodes
with nodes[0] as m, nodes[1] as m2
match path = shortest 1 (m)-[:!TYPE&!HOLDS]-+(m2)
where not any(node in nodes(path) where 'DataCenter' in labels(node) or 'Version' in labels(node) or 'Type' in labels(node))
return path
:params { nodes: [ 'DC1-RCK-1-2-M-3','DC1-RCK-1-4-M-45' ] }
match (N) WHERE N.name in $nodes WITH collect(elementID(N)) as theIDs
WITH theIDs
match (m) where elementId(m) in theIDs
with collect(m) as nodes
with nodes[0] as m, nodes[1] as m2
match path = shortest 1 (m)-[:!TYPE&!HOLDS]-+(m2)
where not any(node in nodes(path) where 'DataCenter' in labels(node) or 'Version' in labels(node) or 'Type' inlabels(node))
return path