0
votes

I'm having a problem using Neo4j at the moment where I want to match two ore more nodes, that are not connected by any path.

Let's say we have a graph with two context components (is this the right word?), for example 4 nodes (A)-->(B) and (C)-->(D).

When I run MATCH (A), (C) in this situation, i get "No Rows" as result, probably because the algorithm can't reach (C) after having chosen (A) as starting node.

How can I still match those nodes?

2
Can you provide de Cypher statements that you are using to create your nodes?Bruno Peres
MATCH (A), (C) should return a Cartesian product between all node pairs... can you create a MVCe in the Neo4j console and share it?Tezra
"probably because the algorithm can't reach (C) after having chosen (A) as starting node." The query engines does not do a traversal, so it can reach nodes that are not connected.Gabor Szarnyas
If your query is something like MATCH (A), (C) RETURN *, and it returns no rows, then the only reasonable explanation is that your DB has no nodes. In that is true, then even MATCH (A) RETURN * should return no nodes.cybersam
I tried to recreate it by doing create (a:A)-[:HAS]->(b:B), (c:C)-[:HAS]->(d:D) and then querying match (a:A),(c:C) return a,c. However it worked. Yesterday I used Neo4j 3.1.0, today I'm using 3.2.2. I'll check it when I get back to my Neo4j 3.1.0Urr4

2 Answers

1
votes

It turns out the problem is caused from something other than Neo4j. I can't recreate it on another computer. The approach to use MATCH (A), (B) was the correct one.

-1
votes

I think you really want MATCH (A) MATCH (C) ... without the comma. This will give you two starting points which you can either RETURN or pass forward with WITH. As Tezra says, using the comma will create a cartesian product.