Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-09-2022 05:36 AM
Hi, I have a graph database of people (nodes) and one type of relationship between them. The relationship has a "strength" property in the form of an integer.
What I am trying to do is:
I would want around 30 nodes to be returned... 10 first order nodes and 2 second order nodes for each of those
I have tried many different queries, typically like this:
MATCH (a:Person {EmailAddress: 'test@test.com'})-[rel]-(b:Person)-[rel2]-(c:Person)
RETURN a, rel, b, rel2, c order by rel.Strength desc, rel2.Strength desc limit 30
My problem is that I am getting one first order node, and 29 second order nodes, "eating up" all my limit of 30.
Is there a way to force a limit on each level? In other words, specify multiple "limit" values?
Thanks
Solved! Go to Solution.
03-09-2022 08:21 AM
Try this. This will give you a list of 20 rows, consisting of the product of the 10 strongest nodes and their two strongest nodes each. I don't understand the 30 limit.
match(a:Person{EmailAddress: 'test@test.com'})-[rel]-(b:Person)
with a, rel.strength as strength_ab, b
order by strength_ab desc
limit 10
with a, strength_ab, b
call{
with b
match(b)-[rel]-(c:Person)
with b, rel.strength as strength_bc, c
order by strength_bc desc
limit 2
return strength_bc, c
}
return a, strength_ab, b, strength_bc, c
03-09-2022 08:21 AM
Try this. This will give you a list of 20 rows, consisting of the product of the 10 strongest nodes and their two strongest nodes each. I don't understand the 30 limit.
match(a:Person{EmailAddress: 'test@test.com'})-[rel]-(b:Person)
with a, rel.strength as strength_ab, b
order by strength_ab desc
limit 10
with a, strength_ab, b
call{
with b
match(b)-[rel]-(c:Person)
with b, rel.strength as strength_bc, c
order by strength_bc desc
limit 2
return strength_bc, c
}
return a, strength_ab, b, strength_bc, c
03-09-2022 09:37 AM
NICE! Worked almost immediately and at first glance it seems to have done what I wanted... Thank you for this, I would not have figured it out easily alone, and your reply opened up a whole new area of things to experiment with 🙂
Thanks again
03-09-2022 11:33 AM
EXCELLENT. It was fun.
All the sessions of the conference are now available online