0
votes

I have a highly interconnected graph where starting from a specific node i want to find all nodes connected to it regardless of the relation type, direction or length. What i am trying to do is to filter out paths that include a node more than 1 times. But what i get is a

Neo.DatabaseError.General.UnknownError: key not found: UNNAMED27

I have managed to create a much simpler database in neo4j sandbox and get the same message again using the following data:

CREATE (n1:Person { pid:1, name: 'User1'}), 
       (n2:Person { pid:2, name: 'User2'}),
       (n3:Person { pid:3, name: 'User3'}), 
       (n4:Person { pid:4, name: 'User4'}),
       (n5:Person { pid:5, name: 'User5'})

With the following relationships:

MATCH (n1{pid:1}),(n2{pid:2}),(n3{pid:3}),(n4{pid:4}),(n5{pid:5})
CREATE (n1)-[r1:RELATION]->(n2), 
       (n5)-[r2:RELATION]->(n2), 
       (n1)-[r3:RELATION]->(n3), 
       (n4)-[r4:RELATION]->(n3)

The Cypher Query that causes this issue in the above model is

MATCH p= (n:Person{pid:1})-[*0..]-(m) 
WHERE ALL(c IN nodes(p) WHERE 1=size(filter(d in nodes(p) where c.pid = d.pid)) ) 
return  m

Can anybody see what is wrong with this query?

2
Tested 3.2.6 and it this error still occursiltzortz

2 Answers

3
votes

The error seems like a bug to me. There is a closed neo4j issue that seems similar, but it was supposed to be fixed in version 3.2.1. You should probably create a new issue for it, since your comments state you are using 3.2.5.

Meanwhile, this query should get the results you seem to want:

MATCH p=(:Person{pid:1})-[*0..]-(m)
WITH m, NODES(p) AS ns
UNWIND ns AS n
WITH m, ns, COUNT(DISTINCT n) AS cns
WHERE SIZE(ns) = cns
return m

You should strongly consider putting a reasonable upper bound on your variable-length path search, though. If you do not do so, then with any reasonable DB size your query is likely to take a very long time and/or run out of memory.

0
votes

When finding paths, Cypher will never visit the same node twice in a single path. So MATCH (a:Start)-[*]-(b) RETURN DISTINCT b will return all nodes connected to a. (DISTINCT here is redundant, but it can affect query performance. Use PROFILE on your version of Neo4j to see if it cares and which is better)

NOTE: This works starting with Neo4j 3.2 Cypher planner. For previous versions of the Cypher planner, the only performant way to do this is with APOC, or add a -[:connected_to]-> relation from start node to all children so that path doesn't have to be explored.)