What you are trying to do is not possible with Spring Data Neo4j repositories. Their purpose is to interact on the entity abstraction and not with arbitrary data like String and Long combined into a map.
But there is a solution to this also in Spring Data Neo4j: The Neo4jClient (Neo4jClient Documentation)
For your example this would be something like:
Collection<Map<String, Object>> all = neo4jClient
.query("match (n:People) return n.group as `group`,count(n) as `num`")
.fetch().all();
Hi, I think I might have a similar problem. I want to use the following query to select a similarity score for a recommendation system:
MATCH (user:LibraryUser {idNumber: $idNumber})-[:hasBorrowed]->(b:Book)<-[:hasBorrowed]-(otherUser:LibraryUser)-[:hasBorrowed]->(recb:Book)
WHERE NOT EXISTS((user)-[:hasBorrowed]->(recb))
WITH recb, COUNT(DISTINCT otherUser) AS sim
RETURN recb AS book, sim AS similarityScore
The ideal solution would be to get a Map<Book, Double>, with the Book as the key and the similarity score as value. The Book Nodes are defined. I tried Gerrits solution above and injected a "Neo4jClient" instead of using the normal repository. However, I can't map the Object that the query returns to a "Book" Node, when I try to cast I get the following error
class org.neo4j.driver.internal.InternalNode cannot be cast to class com.projectfz.Book (org.neo4j.driver.internal.InternalNode is in unnamed module of loader 'app'; com.projectfz.Book is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @3150ae7f)
When I alter the query to return only the title of the Book as well as the score then the returned object can be cast to a String and it works. From this i could get back to the book node, but depending on the number you are returning this will result in quite poor performance. Is there more elegant way that returns the nodes right away?