Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-19-2020 12:47 PM
Hello,
I am currently using Neo4j Community version 3.5.17. I have :Person nodes out of which a few are :Fraud nodes. For a certain :Person node, I would like to find out how many hops away is the closest :Fraud node.
I have used the following queries up till now but I think there might be a better implementation -
MATCH p=shortestPath( (a:Person {fid:''})-[*..6]-(b:Fraud)) RETURN p limit 1;
MATCH path=(a:Person {fid:''})-[*1..6]-(p:Fraud) RETURN a.fid, min(length(path)) AS distance;
Please let me know if there might be some BFS like implementation because the number of nodes grow very fast as the number of hops increase.
Thanks and Regards,
Kevin
Solved! Go to Solution.
04-20-2020 12:10 AM
Using limit
in expandConfig does return only one single path for each person. Is this what you're looking for?
match (n:Person) with n limit 100
call apoc.path.expandConfig(n,{labelFilter:'/Fraud', maxLevel:5, limit:1}) yield path
return n.fid, length(path)
04-19-2020 01:07 PM
Easiest way would be using apoc.path.expand/expandConfig. You can force BFS and use Fraud
as a end node or termination filter and a limit of 1.
04-19-2020 02:09 PM
Hi Stefan,
Thank you. That worked well. However, I now need to find the closest fraud for 100 people. I wrote the following query -
match (n:Person) with n limit 100 call apoc.path.expandConfig(n,{labelFilter:'/Fraud', maxLevel:5}) yield path return n.fid, length(path)
I want to get the first result per person but I don't know how. Please guide me with this.
Thanks and Regards,
Kevin
04-20-2020 12:10 AM
Using limit
in expandConfig does return only one single path for each person. Is this what you're looking for?
match (n:Person) with n limit 100
call apoc.path.expandConfig(n,{labelFilter:'/Fraud', maxLevel:5, limit:1}) yield path
return n.fid, length(path)
All the sessions of the conference are now available online