Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
Specify the direction in findBy Spring data Neo4J queries with depth > 0

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

Until now, I was using findByXXX methods with a depth param equal to 2. Now I need to increase the depth to 3, but the query is far to slow, and I know why : the executed query is not considering the direction of the relationships.

Here is the executed query from the logs (take more than 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 query with a direction, it becomes 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 specify that, in my case, I only want "outgoing" relationships in the findByXXX function declaration of my GraphRepository interface. Is there a parameter like the "@Depth" annotation to give the direction ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

There is currently no way of declaring more fine grained queries through annotations. Actually, having some hints in the code about (not) following some paths can be good for a particular use case, but is irrelevant for others.

Looking at what is done for example on JPA : you can use annotations to eagerly load dependent objects. But once an application grows you have to manage FetchProfiles or NamedEntityGraphs to handle the way you fetch according to the use case.

That is why, with SDN 4.x, the preferred way of doing this is to use custom cypher queries. It will ensure you to pick up only the data you need in a performant way.

There is an issue to track this here. Note that it is one of improvements planned for the next major release of OGM / SDN. If you have specific use cases you need to address or ideas around this, feel free to open a discussion on the the slack channel neo4j-users.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!