Specify direction in findBy Spring Neo4J data with depth> 0

I am using SDN 4.2.1 to save and load nodes and their relationships in Neo4J.

So far I have used findByXXX methods with a depth parameter of 2. Now I need to increase the depth to 3, but the query is much slower and I know why: the executed query does not consider the direction of the relationship.

Here is the executed query from the logs (takes over 20 seconds):

o.n.o.drivers.bolt.request.BoltRequest   : Request: MATCH (n:`Property`) WHERE n.`id` = { `id_0` } WITH n MATCH p=(n)-[*0..3]-(m) RETURN p, ID(n) with params {id_0=P31}

      

When I rewrite the request with a referral it gets very fast:

MATCH (n:`Property`) WHERE n.`id` = "P31" WITH n MATCH p=(n)-[*0..3]->(m) RETURN p, ID(n)

      

I can't find a way to indicate that in my case I only want the "outbound" relationship in the findByXXX function declaration of my GraphRepository interface. Is there a parameter like the "@Depth" annotation to indicate the direction?

+3


source to share


1 answer


There is currently no way to declare finer grained queries via annotations. In fact, some hints in the code (not) by following some paths may be helpful for a specific use case, but for others it doesn't matter.

Looking at what is being done, for example at JPA: you can use annotations to actively load dependent objects. But once the app grows, you need to manage FetchProfiles or NamedEntityGraphs to handle the way you fetch as per use case.



This is why, as of SDN 4.x, the preferred way to do this is using custom cypher queries. This ensures that you can only get the data you need, for real.

There is a problem tracking this here . Please note that this is one of the improvements planned for the next major OGM / SDN release. If you have specific use cases you need to refer to those ideas or ideas, feel free to open a discussion on the weak neo4j-users channel .

+2


source







All Articles