Different shortest results in browser and bloom(2nd case)

< Neo4j Browser >

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.

< Bloom(2.21) Scene Action >

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!

The two results should be the same, but they are not.
Bloom takes too long - there must be something wrong.

They shouldn't be the same ...

Query 1:

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.

1 Like

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.

you don't need apoc ...

: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

It doesn't work. $nodes in Bloom Scene Actions is the list of elementId of nodes selected on the scene.

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.

1 Like

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

what values do you have in $nodes?

: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

$nodes and $relationships are the default variables defined in Scene Actions of Bloom.

Since I don't know what you're using to load the variables - I am just showing you that the query works if you pre-load them.

What I mean is that $nodes is defined by Bloom as elemetId, not by me.

1 Like