Reputation: 147
Currently am working in NEO4J and iam new in graph db. Now i need to paginate the records from graph db. And i created the following query
MATCH (n:Question)<-[r1:HAS_QUESTION]-(c:Chapter)
MATCH (c)-[r2:HAS_CHILD]->(t:Topic)-[r3:HAS_QUESTION]->(qstn:Question)
WHERE ID(c)=330
WITH n,qstn WHERE NOT(n:Removed) AND NOT(qstn:Removed)
WITH n,qstn
RETURN n as Question,qstn
In this query i got 13 question nodes. But when i add skip and limit to that query , i got only 7 nodes instead of 10. The querys is
MATCH (n:Question)<-[r1:HAS_QUESTION]-(c:Chapter)
MATCH (c)-[r2:HAS_CHILD]->(t:Topic)-[r3:HAS_QUESTION]->(qstn:Question)
WHERE id(c)=330 WITH n,qstn
WHERE NOT(n:Removed) AND NOT(qstn:Removed)
WITH n,qstn
RETURN n as Question,qstn
SKIP 0 LIMIT 10;
Somebody please explain what is happening with this query. Is there any idea to get the 10 nodes.
The query for the sample graph is the following.
CREATE (c:Chapter {chapter_name:"Biodiversity and Conservation"})
CREATE (t:Topic {topic_name:"Biodiversity Conservation"})
CREATE (q:Question {content: "first question"})
CREATE (t1:Topic {topic_name:"Biodiversity"})
CREATE (q1:Question {content: "second question"})
CREATE (q0:Question {content: "third question"})
CREATE (q01:Question {content: "fourth question"})
CREATE (q2:Question {content: "fifth question"})
CREATE (q3:Question {content: "sixth question"})
CREATE (q4:Question {content: "seventh question"})
CREATE (q5:Question {content: "eighth question"})
CREATE (q6:Question {content: "nineth question"})
CREATE (q7:Question {content: "tenth question"})
CREATE (q8:Question {content: "eleventh question"})
CREATE (q9:Question {content: "twelfth question"})
CREATE (q10:Question {content: "thirteenth question"})
CREATE (q11:Question {content: "fourteenth question"})
CREATE (q12:Question {content: "fifteenth question"})
CREATE (q13:Question {content: "sixteenth question"})
CREATE (c)-[r:HAS_TOPIC]->(t)
CREATE (c)-[r1:HAS_TOPIC]->(t1)
CREATE (t)-[r2:HAS_QUESTION]->(q)
CREATE (t1)-[r3:HAS_QUESTION]->(q1)
CREATE (c)-[r4:HAS_QUESTION]->(q0)
CREATE (c)-[r5:HAS_QUESTION]->(q01)
CREATE (c)-[r6:HAS_QUESTION]->(q2)
CREATE (c)-[r7:HAS_QUESTION]->(q3)
CREATE (c)-[r8:HAS_QUESTION]->(q4)
CREATE (c)-[r9:HAS_QUESTION]->(q5)
CREATE (c)-[r0:HAS_QUESTION]->(q6)
CREATE (c)-[r11:HAS_QUESTION]->(q7)
CREATE (c)-[r12:HAS_QUESTION]->(q8)
CREATE (c)-[r13:HAS_QUESTION]->(q9)
CREATE (c)-[r14:HAS_QUESTION]->(q10)
CREATE (c)-[r15:HAS_QUESTION]->(q11)
CREATE (c)-[r16:HAS_QUESTION]->(q12)
CREATE (c)-[r17:HAS_QUESTION]->(q13)
return c,t,t1,q0,q01,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,r,r1,r2,r3,r4,r5,r6,r7,r8,r9,r0,r11,
r12,r13,r14,r15,r16,r17
Upvotes: 2
Views: 1205
Reputation: 147
I simplified my query in the following way.. Now it is working without any problem
START c = node({chapter_id})
OPTIONAL MATCH c-[r*..2]->(n:Question)
WHERE NOT(n:Removed)
RETURN DISTINCT n SKIP 0 LIMIT 10;
Upvotes: 0
Reputation: 41676
Which version do you use?
Can you share your graph so that we can reproduce the issue?
I simplified your query, could you try this one?
MATCH (n:Question)<-[:HAS_QUESTION]-(c:Chapter)
WHERE id(c)=330 AND NOT(n:Removed)
MATCH (c)-[:HAS_CHILD]->(t:Topic)-[:HAS_QUESTION]->(qstn:Question)
WHERE NOT(qstn:Removed)
RETURN n,qstn
SKIP 0 LIMIT 10;
Upvotes: 2