I am building a Spring Boot service that connects to a neo4j database via the neo4j-java-driver. One REST endpoint builds a paginated search query with skip and limit that looks like the following:
MATCH (i:Item)-[:HAS_PRICE]->(p:Price)
WHERE p.a>= $aMin AND p.a <= $aMax AND p.b >= $bMin
WITH i, p
ORDER BY p.b asc
SKIP $skip
LIMIT $limit
RETURN i.code
With the query, I am expecting 320 unique items but only get 208. Also on some pages there are duplicate items that were already present in one of the previous pages. When returning all items without skip/limit the result is as expected. When not ordering, the result is also correct. The problem appears to be the combination of ordering with skip/limit.
I also tested the same query on the same database in python with the python neo4j driver version 4.4.2. The skip and limit sizes were the same and the query results were correct, no duplicates. Making the same queries in the Neo4j Browser (with the same skip/limit) does also return the correct results.
So I am thinking that the problem may be with the neo4j-java-driver. I tested it with versions 4.4.8, 5.0.0-alpha03 and 4.0.3. All have the same faulty behavior.
Please ask if you need more information and thank you for helping.