0
votes

I have a question. I am trying to run this query.

START n= NODE(5749,5750,5751,5752,5753,5754,5755,5756,5757,5758,5759,5760) 
MATCH p=(a)-[:KNOWS]-(n)-[:KNOWS]-(b)
OPTIONAL MATCH q=(a)-[:KNOWS]-(b)
RETURN Distinct n.name AS ID,COUNT(distinct p) as NR, COUNT(q) as BR;

The results are bit weird. My DB has 276597 nodes and 401634 relationships in total. But in the result of the above query I have 392502 relationships for one node in graphical view. I found 2 q relationships but in tabular form they are zero!

Here are the results of the above query:

Result of above query

1
Is there something wrong with the cypher query or something is missing. Please correct me if there is something missing. Thanks in advanceCh HaXam
don't quite understand the problem here. Can you reduce the problem to one single start node?Stefan Armbruster

1 Answers

1
votes

Since you did not indicate the directionality of any relationships in your query, your counts include duplicates (notice that all your results are even numbers).

This slightly modified version of your query should get better results (you should use whatever directionality applies to your use case):

START n= NODE(5749,5750,5751,5752,5753,5754,5755,5756,5757,5758,5759,5760) 
MATCH p=(a)-[:KNOWS]->(n)-[:KNOWS]->(b)
OPTIONAL MATCH q=(a)-[:KNOWS]-(b)
RETURN Distinct n.name AS ID,COUNT(distinct p) as NR, COUNT(q) as BR;

The OPTIONAL MATCH clause still does not specify any directionality, since I presumed that you really wanted to get both directions in that case. But you should also specify directionality in that clause, if appropriate.