Hello everyboy,
I'm having a problem with Neo4j (v. 5.3.0) and Spring Data Neo4j (v. 6.3.7) for which I have not found any solution here at the moment.
I'm working on a DB with more than 15 millions of nodes so I'm putting some effort to optimize my queries with such a large dataset.
While doing some query tuning with PROFILE, I've identified a potential bottleneck, during the ProduceResults step. My goal is to run a 5-hops exploration from a central node and right now, with a complex use case, I reach 16.5 millions DB hits with a duration in the order of minutes (not so good). That's because for each node and relationships in the paths explored, Neo4j reads and returns all the properties of these entities (each node can have up to 50 different properties!).
Since I'm only interested in a small subset of these properties, what I have in mind is to find a way to return a node (with its metadata) but with only some properties instead of all.
For simplicity, let's say that I want to run a query like this:
MATCH (p:Person)-[r:SUPERVISES]->(m:Person)
WHERE p.IDENTIFIER = '...'
RETURN p, collect(r), collect(m)
With SDN, I can get a Person object with a list of SUPERVISES relationships, each with a reference to the other Person related.
The reason I wrote no Projections in the title is because I don't think I can solve my problem with a simple Map Projection. If I write something like this:
RETURN p {.prop1, .prop2}, collect(r), collect(m {.prop1, .prop2})
the SDN object has the properties of my choice but no information about the relationships, because Neo4j is not returning a Node object but a list of properties.
Once I figured out the problem, I thought I solved it with queries like these:
RETURN {identity: id(p), labels: labels(p), properties: {prop1: p.prop1, prop2: p.prop2}} AS p,
collect(r), {identity: id(m), labels: labels(m), properties: {prop1: m.prop1, prop2: m.prop2}} AS m
or
RETURN p {__internalNeo4jId__: id(p), __nodeLabels__: labels(p), .prop1, .prop2},
collect(r), m {__internalNeo4jId__: id(m), __nodeLabels__: labels(m), .prop1, .prop2}
to match the results with the metadata Neo4j returns in the initial case. But, while I still get the properties of my choice in the SDN object, I can't get the relationships lists populated, which is essential for the application.
So so that brings me back to the question: it is possible to get the information of a node from Neo4j to SDN but only with a subset of properties?
P.S.: the reason I want to solve this problem on the SDN side is because the queries, like the one I showed you, run just fine and helped me to turn down that 16.5 millions DB hits to only 1.7 millions.